-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
datetime.tzinfo
is abtract
#8908
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
Conversation
This comment has been minimized.
This comment has been minimized.
I was following return types from https://docs.python.org/3/library/datetime.html#datetime.timezone |
|
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/builders/gettext.py:191:7: error: Cannot instantiate abstract class "LocalTimeZone" with abstract attribute "tzname" [abstract]
|
Example in Sphinx is technically correct: class LocalTimeZone(tzinfo):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.tzdelta = tzdelta
def utcoffset(self, dt: Optional[datetime]) -> timedelta:
return self.tzdelta
def dst(self, dt: Optional[datetime]) -> timedelta:
return timedelta(0)
ltz = LocalTimeZone()
I will send a PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add the metaclass, since runtime doesn't have it? mypy allows for checking abstractmethod without metaclass
Yes, we sometimes need this. Please, take a look at this error:
|
Basically, |
Oh interesting, didn't realise there was this stub-only check: https://github.com/python/mypy/blob/5e1e26eba15b43449bdce4010bf16d160d3ec505/mypy/semanal_classprop.py#L97 |
We need the metaclass change in |
This class is not marked as abstract, but it is documented:
Source: https://github.com/python/cpython/blob/f6b1e4048dc353aecfbfbae07de8212900632098/Lib/datetime.py#L1222-L1243