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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stubs for pytz #3393

Merged
merged 3 commits into from
Oct 30, 2019
Merged

Conversation

angelaambroz
Copy link
Contributor

馃憢 First commit. Coming here from pandas, specifically #28926.

  • (.venv3)$ python3 tests/mypy_test.py
  • (.venv3)$ python3 tests/mypy_selftest.py
  • (.venv3)$ flake8
  • (.venv3)$ python3 tests/pytype_test.py

I'm flagging this PR as WIP until I get confirmation on one type I'm unsure of (_tzinfos kwarg in FixedOffset). I'll open an issue in pytz to confirm that there; and will remove the "WIP" label once that's confirmed.

@@ -29,6 +29,7 @@ class NonExistentTimeError(InvalidTimeError): ...
utc: _UTCclass
UTC: _UTCclass
def timezone(zone: str) -> Union[_UTCclass, _StaticTzInfo, _DstTzInfo]: ...
def FixedOffset(offset: int) -> Union[_UTCclass, _StaticTzInfo, _DstTzInfo]: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like FixedOffset is an ad-hoc implementation.

If offset is 0, it returns a _UTCclass.

If offset is not 0, it returns a class _FixedOffset. This class is not a subclass of BaseTzInfo, though it is compatible with its interface, except for zone being None. It also implements utcoffset (without a is_dst argument), dst and tzname (returning None). So it doesn't fit with any of the existing classes.

A bit of a mess! I suppose you can add a _FixedTzInfo class which encodes all of that, not sure if it's worth it. Otherwise, you should change the type to Union[_UTCclass, tzinfo].

Copy link
Member

Choose a reason for hiding this comment

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

Agree with bluetech here. The current return type seems suboptimal, because we generally discourage Union return types, and in fact it doesn't ever return a _StaticTzInfo or a _DstTzInfo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

馃憤 Thanks, both. And apologies for the silence - got sucked into other work. I can change the return type to Union[_UTCclass, tzinfo], per bluetech's comment. Will make the change, run the tests locally, and push it up now.

@@ -1,4 +1,4 @@
from typing import Optional, List, Set, Mapping, Union
from typing import Optional, List, Set, Mapping, Union, Dict
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to remove the Dict.

@angelaambroz angelaambroz changed the title WIP: Update stubs for pytz Update stubs for pytz Oct 25, 2019
@JelleZijlstra JelleZijlstra merged commit b5b9a39 into python:master Oct 30, 2019
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.

None yet

3 participants