Skip to content

pytz: rework stubs#6551

Merged
srittau merged 5 commits into
python:masterfrom
JelleZijlstra:pytz
Dec 9, 2021
Merged

pytz: rework stubs#6551
srittau merged 5 commits into
python:masterfrom
JelleZijlstra:pytz

Conversation

@JelleZijlstra
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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