[Datetime-SIG] Making dt parameter of timezone.tzname(dt) optional
tim.peters at gmail.com
Wed Sep 9 18:33:28 CEST 2015
[Berker Peksağ <berker.peksag at gmail.com>]
> The idea was came up when I reviewed issue 22241  and Alexander
> said "This is a reasonable request":
> 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.
>  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
More information about the Datetime-SIG