[Berker Peksağ <[email protected]>]
> The idea was came up when I reviewed issue 22241 [1] and Alexander
> said "This is a reasonable request":
>
>     http://bugs.python.org/review/22241/
>
> Currently, we have tests like (see Lib/test/datetimetester.py)
>
>     self.assertEqual('UTC', timezone.utc.tzname(None))
>     self.assertEqual('UTC', timezone(ZERO).tzname(None))
>     self.assertEqual('UTC-05:00', timezone(-5 * HOUR).tzname(None))
>     self.assertEqual('UTC+09:30', timezone(9.5 * HOUR).tzname(None))
>
> Can we just make dt optional and set its default value to None in Python 3.6? 
> So
>
>    timezone.utc.tzname(None) and timezone.utc.tzname()
>
> will both return "UTC". It's a small change, but I think it will make
> the API cleaner.
>
> --Berker
>
> [1] http://bugs.python.org/issue22241

+0.  The base (tzinfo) class requires the datetime argument because,
in general, a zone's name depends on the datetime (like "is it in the
zone's "daylight" time"?).

A subclass (like `timezone`) is free to override it to remove that
requirement, but then code relying on the simplification is also
relying on that it will only ever see instances of that subclass.
General code can't make that assumption and get away with it.

The lines from the test suite can't possibly ever see anything except
the exact instance each is testing, so can't ever suffer that kind of
problem.  But it's also no real burden to add a few "None"s in the
test suite.  Snippets from test suites rarely make compelling examples
either way - they're so very specific to the tiny bit of behavior
they're probing.
_______________________________________________
Datetime-SIG mailing list
[email protected]
https://mail.python.org/mailman/listinfo/datetime-sig
The PSF Code of Conduct applies to this mailing list: 
https://www.python.org/psf/codeofconduct/

Reply via email to