Issue 36720: Correct Should to Must in Definition of object.len (original) (raw)
Issue36720
Created on 2019-04-25 14:52 by Michal Kononenko, last changed 2022-04-11 14:59 by admin. This issue is now closed.
Messages (2) | ||
---|---|---|
msg340844 - (view) | Author: Michal Kononenko (Michal Kononenko) | Date: 2019-04-25 14:52 |
The link below defines __len__ https://docs.python.org/3/reference/datamodel.html?highlight=__len__#object.__len__ However, I was reading in the StackOverflow thread below that CPython does some validation to check that the return value of __len__ should be >= 0. Does this mean that len must return a value >= 0, in the RFC 2119 sense of the word? https://stackoverflow.com/questions/42521449/how-does-python-ensure-the-return-value-of-len-is-an-integer-when-len-is-cal | ||
msg340851 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
Date: 2019-04-25 17:53 |
There is probably validation code in len(), but the method itself can do whatever it wants if you call it directly. So the documentation is accurate in saying the method _should_ return >= 0 but that there's nothing strictly enforcing that in Python for that specific method when defined and called directly. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:59:14 | admin | set | github: 80901 |
2019-04-25 17:53:14 | brett.cannon | set | status: open -> closednosy: + brett.cannonmessages: + resolution: not a bugstage: resolved |
2019-04-25 14:52:18 | Michal Kononenko | create |