This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: datetime.timezone methods require datetime object
Type: behavior Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, poke, r.david.murray
Priority: normal Keywords:

Created on 2014-08-11 14:17 by poke, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg225188 - (view) Author: Patrick Westerhoff (poke) Date: 2014-08-11 14:17
I’ve noticed that the methods in `datetime.timezone` all require a datetime object (or explicitely `None`) as its parameter or they will raise an exception.

The datetime object however is never required for the implementation of the method, so it seems to me like an unnecessary requirement, given that timezone objects are completely independent of datetime objects.

For example `timezone.utcoffset` is implemented like this:

    def utcoffset(self, dt):
        if isinstance(dt, datetime) or dt is None:
            return self._offset
        raise TypeError("utcoffset() argument must be a datetime instance"
                        " or None")

I don’t really understand this requirement and if there isn’t an actual reason for it (if there is, it should be documented somewhere), I’d suggest to remove this requirement completely. For backwards compatibility, the parameter could simply default to `None`.
msg225189 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-08-11 14:29
A timezone is a particular implementation of the general tzinfo API, and in the general case the datetime argument *is* required.  This is already documented (ie: that timezone is a concrete implementation of tzinfo, and that the tzinfo API requires the datetime).
msg225190 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2014-08-11 14:48
As David explained, utcoffset() method signature is dictated by the base class.  This is not a bug.
History
Date User Action Args
2022-04-11 14:58:06adminsetgithub: 66379
2014-08-11 14:48:54belopolskysetstatus: open -> closed
resolution: not a bug
messages: + msg225190

stage: resolved
2014-08-11 14:29:23r.david.murraysetnosy: + r.david.murray, belopolsky
messages: + msg225189
2014-08-11 14:17:13pokecreate