-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: lazify type-check import #28342
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
Merged
+2
−5
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
its not obvious to me why these only care about dateutil tzinfos and not e.g. stdlib or pytz versions. @simonjayhawkins any idea?
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.
These were the types seen by MonkeyType. I think they are resolving to Any.
i've since abandoned using MonkeyType for a couple of reasons..
MonkeyType uses nominal types and in many cases these resolve to Any due to unfollowed imports.
MonkeyType only adds nominal types whereas we'd probably prefer structural types.
feel free to change or remove. The order of typing priority from high to low should probably match the order used in isort. so I consider these to be low priority type hints.
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.
OK. I would be shocked if these weren't supposed to be
tzinfo
, will look more closely and update.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.
yes, but if tzinfo is an unfollowed import, it'll just resolve to Any.
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.
what determines whether something is an unfollowed import? tzinfo is stdlib, seems like mypy should know what it is
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.
Revealed type for
tz
isUnion[Any, dateutil.tz.tz.tzutc, None]
so it is only the
dateutil.zoneinfo.tzfile
that is unfollowed.pytz.tzinfo.DstTzInfo
is also unknown to mypy.since all three (
dateutil.zoneinfo.tzfile
,dateutil.tz.tz.tzutc
andpytz.tzinfo.DstTzInfo
) inherit fromdatetime.tzinfo
, anddatetime.tzinfo
is known to mypy through the stdlib, then it probably does make sense to usedatetime.tzinfo
here.However, within the function,
tz
is only used inTimestamp(x).tz_convert(tz)
andTimestamp(x).tz_localize(tz)
and Timestamp resolves to any due to an unfollowed import. (needs stub #28195) so no actual type checking is being performed.so probably best just to delete the type hint for now.