On Lack of Default __len__
in Python Abstract Base Classes
#122410
Labels
module: data
torch.utils.data
module: docs
Related to our documentation, both in docs/ and docblocks
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Thoughts about
# NOTE [ Lack of Default __len__ in Python Abstract Base Classes ]
.TL;DR:
__len__
("abstract") methods but seems like they could be (via aTypeError
or an abstract method implementations).__len__
docstrings but they could be (without the method itself).We have https://github.com/pytorch/pytorch/blob/v2.2.1/torch/utils/data/sampler.py#L70-L95 (introduced in #19228):
But what should return
len(subclass_instance)
without an implemented length value?No matter, on other hand,
NotImplemented
is for binary operators only.Let's remove this part of the comment?
This comment says we should write
list(iter(X))
instead oflist(X)
. (See thelist
cconstructor documentation.)It is a good idea, isn't it? This comment says it is the correct one.
More options:
This comment suggest to make an abstract method.
Are we able to add the documentation stub (without the method itself)?
Thanks!
cc @svekars @brycebortree @VitalyFedyunin @ejguan @dzhulgakov @ssnl
The text was updated successfully, but these errors were encountered: