Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime.timezone methods require datetime object #66379

Closed
poke mannequin opened this issue Aug 11, 2014 · 3 comments
Closed

datetime.timezone methods require datetime object #66379

poke mannequin opened this issue Aug 11, 2014 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@poke
Copy link
Mannequin

poke mannequin commented Aug 11, 2014

BPO 22183
Nosy @abalkin, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2014-08-11.14:48:54.903>
created_at = <Date 2014-08-11.14:17:13.372>
labels = ['invalid', 'type-bug', 'library']
title = 'datetime.timezone methods require datetime object'
updated_at = <Date 2014-08-11.14:48:54.901>
user = 'https://bugs.python.org/poke'

bugs.python.org fields:

activity = <Date 2014-08-11.14:48:54.901>
actor = 'belopolsky'
assignee = 'none'
closed = True
closed_date = <Date 2014-08-11.14:48:54.903>
closer = 'belopolsky'
components = ['Library (Lib)']
creation = <Date 2014-08-11.14:17:13.372>
creator = 'poke'
dependencies = []
files = []
hgrepos = []
issue_num = 22183
keywords = []
message_count = 3.0
messages = ['225188', '225189', '225190']
nosy_count = 3.0
nosy_names = ['belopolsky', 'r.david.murray', 'poke']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue22183'
versions = []

@poke
Copy link
Mannequin Author

poke mannequin commented Aug 11, 2014

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.

@poke poke mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 11, 2014
@bitdancer
Copy link
Member

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

@abalkin
Copy link
Member

abalkin commented Aug 11, 2014

As David explained, utcoffset() method signature is dictated by the base class. This is not a bug.

@abalkin abalkin closed this as completed Aug 11, 2014
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants