[New-bugs-announce] [issue22183] datetime.timezone methods require datetime object

Patrick Westerhoff report at bugs.python.org
Mon Aug 11 16:17:13 CEST 2014

New submission from Patrick Westerhoff:

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`.

components: Library (Lib)
messages: 225188
nosy: poke
priority: normal
severity: normal
status: open
title: datetime.timezone methods require datetime object
type: behavior

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list