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

pytz: rework stubs #6551

Merged
merged 5 commits into from
Dec 9, 2021
Merged

pytz: rework stubs #6551

merged 5 commits into from
Dec 9, 2021

Conversation

JelleZijlstra
Copy link
Member

It's important for pyanalyze that classes are actually in the file they're claimed to be in.

@srittau srittau merged commit 384e309 into python:master Dec 9, 2021
@JelleZijlstra JelleZijlstra deleted the pytz branch December 9, 2021 14:36
@terencehonles
Copy link
Contributor

@JelleZijlstra I'm running into an issue specifying basically the return type coming from pytz.timezone(...). I would like to write something like pytz.tzinfo.StaticTzInfo | pytz.tzinfo.DstTzInfo | type[pytz.UTC] or pytz.tzinfo.StaticTzInfo | pytz.tzinfo.DstTzInfo | Literal[pytz.UTC] but that doesn't seem to work. I can use pytz._UTCclass but that needs to be only in the type annotation and cannot be used in a type alias.

Is there a better way to say whatever a method returns? The reason I'm running into the issue is I have something like:

tz = pytz.UTC
try:
    tz = pytz.timezone(timezone_name)
except pytz.UnknownTimeZoneError:
    pass

and previously I declared the variable pytz.BaseTzInfo so that it would not be too strict, but now I cannot use that since that class doesn't define localize, which is what I then use.

@srittau
Copy link
Collaborator

srittau commented Dec 13, 2021

@JelleZijlstra I think it would make sense to add localize() etc. back to BaseTzInfo as abstract methods, even if the implementation doesn't do that. It seems all subclasses implement these six methods. What do you think?

@JelleZijlstra
Copy link
Member Author

I'm OK with that.

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.

3 participants