-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Use checkmember.py to check protocol subtyping #18943
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
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a3cdf8
Use checkmember.py to check protocol subtyping
ilevkivskyi 9c3d303
show mypy primer speed regression
hauntsaninja 738a1d7
Merge branch 'master' into checkmember-proto
hauntsaninja 4b08554
Merge remote-tracking branch 'upstream/master' into checkmember-proto
ilevkivskyi 5b3190a
Put type checker global state in separate module
ilevkivskyi fac2854
Merge branch 'checkmember-proto' of https://github.com/ilevkivskyi/my…
ilevkivskyi 689c119
Add dedicated tests for key resolved issues
ilevkivskyi 04f3e08
Merge branch 'master' into checkmember-proto
ilevkivskyi 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
Put type checker global state in separate module
- Loading branch information
commit 5b3190a1670ee5ddcc0e9f0d4d92c251d3243a63
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterator | ||
| from contextlib import contextmanager | ||
| from typing import Final | ||
|
|
||
| from mypy.checker_shared import TypeCheckerSharedApi | ||
|
|
||
| # This is global mutable state. Don't add anything here unless there's a very | ||
| # good reason. | ||
|
|
||
|
|
||
| class TypeCheckerState: | ||
| # Wrap this in a class since it's faster that using a module-level attribute. | ||
|
|
||
| def __init__(self, type_checker: TypeCheckerSharedApi | None) -> None: | ||
| # Value varies by file being processed | ||
| self.type_checker = type_checker | ||
|
|
||
| @contextmanager | ||
| def set(self, value: TypeCheckerSharedApi) -> Iterator[None]: | ||
| saved = self.type_checker | ||
| self.type_checker = value | ||
| try: | ||
| yield | ||
| finally: | ||
| self.type_checker = saved | ||
|
|
||
|
|
||
| checker_state: Final = TypeCheckerState(type_checker=None) |
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
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
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
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.
Most of the remaining performance regression comes from
find_member. Would it be feasible to add a fast path that could be used in the majority of (simple) cases? This only makes sense if the semantics would remain identical. We'd first try the fast path, and if it can't be used (not a simple case), we'd fall back to the general implementation that is added here (afterfrom mypy.checkmember import ...). The fast path might look a bit likefind_member_simple.That fast path might cover access to normal attribute/method via instance when there are no self types or properties, for example. Maybe we can avoid creating
MemberContextand usingfilter_errors.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.
This may be harder to tune, so although I agree we should do this, i would leave this optimization for later.