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

Stub methods for abstract tzinfo to allow usage with mypy 1.0.0 #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andersk
Copy link

@andersk andersk commented Mar 4, 2023

Fixes #125. Ported from python/typeshed@de0b366.

@pganssle
Copy link
Owner

pganssle commented Mar 4, 2023

Hm. Kind of a weird choice on mypy's part, because tzinfo is not actually an abstract class, it just... practically is. Still, this doesn't hurt anything, so let's go for it.

src/backports/zoneinfo/__init__.pyi Show resolved Hide resolved
@@ -30,6 +30,9 @@ class ZoneInfo(tzinfo):
) -> _T: ...
@classmethod
def clear_cache(cls, *, only_keys: Iterable[str] = ...) -> None: ...
def tzname(self, __dt: datetime | None) -> str | None: ...
def utcoffset(self, __dt: datetime | None) -> timedelta | None: ...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too concerned with this since it's maybe better taken up with typeshed, but I am not sure that these are actually the right type signatures for these functions.

They can take a time as well, and they never return None if you pass them a datetime, so the correct signatures are probably:

@overload
def utcoffset(self, __dt: datetime) -> timedelta: ...

@overload
def utcoffset(self, __dt: Union[time, None]) -> Union[timedelta, None]: ...

I created a PR upstream in typeshed for discussion: python/typeshed#9862

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I continue to request that this be merged as-is, because the purpose of a backport is to optimize compatibility with the released upstream version, not to pursue incompatible improvements. Obviously you’re welcome to continue pursuing those improvements upstream, and then we can backport them here in the future. But there’s no reason to block this current backport on that.

@andersk
Copy link
Author

andersk commented Jul 10, 2023

The typeshed and mypy issues aren’t going to be straightforward to resolve. Would you be open to merging and releasing this now, so that the library can be used with mypy ≥ 1.0.0, and we can later update it for future typeshed and mypy fixes as appropriate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect stub file causes type checking error
3 participants