[Python-ideas] Please reconsider the Boolean evaluation of midnight
Markus Unterwaditzer
markus at unterwaditzer.net
Thu Mar 6 08:53:46 CET 2014
On 6 March 2014 08:40:24 CET, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
>On Thu, Mar 6, 2014 at 2:30 AM, Donald Stufft <donald at stufft.io> wrote:
>
>> It’s not reasonable to expect that midnight will evaluate
>> to false, ..
>>
>
>Only in the world where it is not reasonable to expect programmers to
>read
>library documentation.
I disagree. Consider this code:
class MyType:
def __bool__(self):
return bool(random.random())
Even though the behavior in boolean context is documented, it doesn't have to make any sense or be reasonable.
>In my world it is reasonable to expect that the
>behavior that was documented in 10 major versions and for 10 years can
>be
>relied on.
>
It *is* reasonable to expect to be able to rely on such features, yet IMO it is not reasonable to actually rely on that feature, for reasons of readability already mentioned by me in a reply to Steven D'Aprano. Considering that (from my subjective view) many people new to Python expect the kind of behavior proposed by the OP, i think it might be time for a change. Maybe an actual survey is the only way to find out.
>
>
>> especially when it doesn’t if you happen to have a tzinfo on the time
>> (sometimes!).
>>
>
>As long as tzinfo specifies a fixed offset, there is no problem with
>the
>current definition. If you are unfortunate enough to live in a place
>with
>semi-annual DST adjustment, aware time objects are problematic for
>reasons
>that have nothing to do with the discussion at hand.
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Python-ideas mailing list
>Python-ideas at python.org
>https://mail.python.org/mailman/listinfo/python-ideas
>Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas
mailing list