4 ms·
While I agree this is surprising behavior and I wouldn't design an API this way, it is documented behavior. From the docs: "in Boolean contexts, a time object
by nas 13y ago
While I agree this is surprising behavior and I wouldn't design an API this way, it is documented behavior. From the docs:
"in Boolean contexts, a time object is considered to be true if and only if, after converting it to minutes and subtracting utcoffset() (or 0 if that’s None), the result is non-zero"
Changing at this point would possibly break code that relied on documented library behavior. That's not a responsible thing to do.
- RyanMcGreal 13y agoExplicit is better than implicit. Simple is better than complex.
- nas 13y agoI'm not sure what that is supposed to mean in this context. Testing for "is not None" is more explicit and avoids the trap being discussed. I don't know how the second sentence applies, maybe "if timeval:" is simpler? BTW, do you know the original author of the Zen of Python has posted to this very dicussion (while also being the orginal author of said module): https://mail.python.org/pipermail/python-ideas/2014-March/026573.html https://mail.python.org/pipermail/python-ideas/2014-March/02... https://mail.python.org/pipermail/python-ideas/2014-March/026577.html https://mail.python.org/pipermail/python-ideas/2014-March/02...
- Pacabel 13y ago"Simplicity" is not measured in terms of key presses or characters. The "if timeval:" case may contain fewer characters, but it's less explicit. Being less explicit opens it up to greater ambiguity. Ambiguity is a form of complexity. Complexity is the opposite of simplicity. The explicit "is not None" check may require more typing, but it's far more explicit and exact. That means it's much less ambiguous, and thus less complex, and thus exhibits greater simplicity.
- freyrs3 13y agoThe word "simple" means many things to many people, it's probably the most ambiguous line in the Zen of Python.
- mercurial 13y agoThat's why the user was suggesting deprecating the feature.
- mikeash 13y agoI really have to wonder if there is actually any code out there that relies on it. Even given Python's great popularity, I would not be surprised if fixing this broke nothing at all.
- kisstheblade 13y agoHow about some loop that wants to break or do something when the day changes while incrementing the date? Never used python and don't know if this is how things are done there, just a thought.