Uh oh!
There was an error while loading. Please reload this page.
datetime.tzinfo is abtract - #8908
Conversation
This comment has been minimized.
This comment has been minimized.
sobolevn
commented
Oct 16, 2022
I was following return types from https://docs.python.org/3/library/datetime.html#datetime.timezone |
sobolevn
commented
Oct 16, 2022
|
sobolevn
commented
Oct 16, 2022
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] |
sobolevn
commented
Oct 16, 2022
Example in Sphinx is technically correct: classLocalTimeZone(tzinfo):
def__init__(self, *args: Any, **kwargs: Any) ->None:
super().__init__(*args, **kwargs)
self.tzdelta=tzdeltadefutcoffset(self, dt: Optional[datetime]) ->timedelta:
returnself.tzdeltadefdst(self, dt: Optional[datetime]) ->timedelta:
returntimedelta(0)
ltz=LocalTimeZone()
I will send a PR. |
hauntsaninja
left a comment
There was a problem hiding this comment.
Do we need to add the metaclass, since runtime doesn't have it? mypy allows for checking abstractmethod without metaclass
sobolevn
commented
Oct 17, 2022
Yes, we sometimes need this. Please, take a look at this error: |
sobolevn
commented
Oct 17, 2022
Basically, |
hauntsaninja
commented
Oct 17, 2022
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