-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: new mypyc primitives for weakref.proxy #19217
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 14 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d29eab8
add tests
BobTheBuidler d043cda
_weakref stubs
BobTheBuidler 81760b2
weakref stubs
BobTheBuidler e790625
feat: new primitive for weakref.ref
BobTheBuidler 1bcc358
feat(test): test ir
BobTheBuidler 996987c
fix: steal maybe
BobTheBuidler 3bcada6
feat(test): split up run tests
BobTheBuidler 9d6c52c
Update weakref_ops.py
BobTheBuidler 1c96658
finalize PR
BobTheBuidler 652de32
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 28129f3
Merge branch 'master' into weak-proxy
BobTheBuidler c58f827
Merge branch 'master' into weak-proxy
BobTheBuidler 5f13dbf
Merge branch 'master' into weak-proxy
BobTheBuidler d6b8d6b
Merge branch 'master' into weak-proxy
BobTheBuidler 23d89a2
rip out pytest.raises
BobTheBuidler c4f596e
rip out driver.py
BobTheBuidler fe03dd6
combine run tests
BobTheBuidler 2667ae8
test callback is called
BobTheBuidler 4d39829
Update run-weakref.test
BobTheBuidler 54cbf90
Merge branch 'master' into weak-proxy
BobTheBuidler 78694f3
Update run-weakref.test
BobTheBuidler 5c9cab5
Update run-weakref.test
BobTheBuidler 92a1f8a
Merge branch 'master' into weak-proxy
BobTheBuidler da8e23a
remove test-weakref.pyi
BobTheBuidler 9fa4a16
Merge branch 'weak-proxy' of https://github.com/BobTheBuidler/mypy in…
BobTheBuidler 05513a8
add type annotations
BobTheBuidler fd7632c
add `ReferenceType.__call__` to stubs
BobTheBuidler 5eaaefe
Merge branch 'master' into weak-proxy
BobTheBuidler fb9e02d
fix mypy errs
BobTheBuidler 8f5bf72
disable error code union-attr
BobTheBuidler 5563d05
fix: use Optional instead of |
BobTheBuidler 796d5ce
fix stubs
BobTheBuidler 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
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,10 @@ | ||
| class dict: ... | ||
| class ellipsis: ... | ||
| class int: ... | ||
| class str: ... | ||
| class tuple: ... | ||
| class type: ... | ||
| class list: ... | ||
| class BaseException: ... | ||
| class Exception(BaseException): ... | ||
| class ReferenceError(Exception): ... | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from typing import Any, Callable, TypeVar, overload | ||
| from weakref import CallableProxyType | ||
|
|
||
| _C = TypeVar("_C", bound=Callable[..., Any]) | ||
| _T = TypeVar("_T") | ||
|
|
||
| # Return CallableProxyType if object is callable, ProxyType otherwise | ||
| @overload | ||
| def proxy(object: _C, callback: Callable[[_C], Any] | None = None, /) -> CallableProxyType[_C]: ... | ||
| @overload | ||
| def proxy(object: _T, callback: Callable[[_T], Any] | None = None, /) -> Any: ... |
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 |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| from _weakref import proxy | ||
| from collections.abc import Callable | ||
| from typing import Any, Generic, TypeVar | ||
| from typing import Any, ClassVar, Generic, TypeVar, final | ||
| from typing_extensions import Self | ||
|
|
||
| _C = TypeVar("_C", bound=Callable[..., Any]) | ||
| _T = TypeVar("_T") | ||
|
|
||
| class ReferenceType(Generic[_T]): # "weakref" | ||
| __callback__: Callable[[Self], Any] | ||
| def __new__(cls, o: _T, callback: Callable[[Self], Any] | None = ..., /) -> Self: ... | ||
|
|
||
| ref = ReferenceType | ||
|
|
||
| @final | ||
| class CallableProxyType(Generic[_C]): # "weakcallableproxy" | ||
| def __eq__(self, value: object, /) -> bool: ... | ||
| def __getattr__(self, attr: str) -> Any: ... | ||
| __call__: _C | ||
| __hash__: ClassVar[None] # type: ignore[assignment] | ||
|
|
||
| __all__ = ["proxy"] |
Oops, something went wrong.
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.
This fixture is probably causing the problems -- some of these definitions are too simplified (or missing). If
ReferenceErroris the only new thing you need here, what about adding it to the genericir.py?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.
Ah, I saw a comment somewhere indicating not to add things to that file as it would slow down the whole suite.
No worries, I've updated the PR accordingly and the tests pass now.
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.
Yeah, we prefer not to add too many things to the file, but sometimes it's just too much effort to avoid doing this.