-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Use tuple[object, ...]
and dict[str, object]
as upper bounds for ParamSpec.args
and ParamSpec.kwargs
#12668
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
+186
−47
Merged
Use tuple[object, ...]
and dict[str, object]
as upper bounds for ParamSpec.args
and ParamSpec.kwargs
#12668
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1c5c612
Use `tuple[Any, ...]` and ``dict[str, Any]` as fallbacks for `ParamSp…
AlexWaygood a8d623e
Fix newly broken tests
AlexWaygood 4616473
Add new test
AlexWaygood b9ddfcb
Make new test pass
AlexWaygood b9b98b9
Add newline at end of file
AlexWaygood 5ff2309
Cleanup the diff a little bit
AlexWaygood e1812ab
Minor style cleanup for the new stub
AlexWaygood 7f372f9
Use `object` instead of `Any`
AlexWaygood 913e903
Merge branch 'paramspec-args-kwargs' of https://github.com/AlexWaygoo…
AlexWaygood 0b71fca
Fix
AlexWaygood e57f9e5
Address review
AlexWaygood 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
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,76 @@ | ||
# builtins stub for paramspec-related test cases | ||
|
||
from typing import ( | ||
Sequence, Generic, TypeVar, Iterable, Iterator, Tuple, Mapping, Optional, Union, Type, overload, | ||
Protocol | ||
) | ||
|
||
T = TypeVar("T") | ||
T_co = TypeVar('T_co', covariant=True) | ||
KT = TypeVar("KT") | ||
VT = TypeVar("VT") | ||
|
||
class object: | ||
def __init__(self) -> None: ... | ||
|
||
class function: ... | ||
class ellipsis: ... | ||
|
||
class type: | ||
def __init__(self, *a: object) -> None: ... | ||
def __call__(self, *a: object) -> object: ... | ||
|
||
class list(Sequence[T], Generic[T]): | ||
@overload | ||
def __getitem__(self, i: int) -> T: ... | ||
@overload | ||
def __getitem__(self, s: slice) -> list[T]: ... | ||
def __contains__(self, item: object) -> bool: ... | ||
def __iter__(self) -> Iterator[T]: ... | ||
|
||
class int: | ||
def __neg__(self) -> 'int': ... | ||
|
||
class bool(int): ... | ||
class float: ... | ||
class slice: ... | ||
class str: ... | ||
class bytes: ... | ||
|
||
class tuple(Sequence[T_co], Generic[T_co]): | ||
def __new__(cls: Type[T], iterable: Iterable[T_co] = ...) -> T: ... | ||
def __iter__(self) -> Iterator[T_co]: ... | ||
def __contains__(self, item: object) -> bool: ... | ||
def __getitem__(self, x: int) -> T_co: ... | ||
def __mul__(self, n: int) -> Tuple[T_co, ...]: ... | ||
def __rmul__(self, n: int) -> Tuple[T_co, ...]: ... | ||
def __add__(self, x: Tuple[T_co, ...]) -> Tuple[T_co, ...]: ... | ||
def __len__(self) -> int: ... | ||
def count(self, obj: object) -> int: ... | ||
|
||
class _ItemsView(Iterable[Tuple[KT, VT]]): ... | ||
|
||
class dict(Mapping[KT, VT]): | ||
@overload | ||
def __init__(self, **kwargs: VT) -> None: ... | ||
@overload | ||
def __init__(self, arg: Iterable[Tuple[KT, VT]], **kwargs: VT) -> None: ... | ||
def __getitem__(self, key: KT) -> VT: ... | ||
def __setitem__(self, k: KT, v: VT) -> None: ... | ||
def __iter__(self) -> Iterator[KT]: ... | ||
def __contains__(self, item: object) -> int: ... | ||
def update(self, a: Mapping[KT, VT]) -> None: ... | ||
@overload | ||
def get(self, k: KT) -> Optional[VT]: ... | ||
@overload | ||
def get(self, k: KT, default: Union[KT, T]) -> Union[VT, T]: ... | ||
def __len__(self) -> int: ... | ||
def pop(self, k: KT) -> VT: ... | ||
def items(self) -> _ItemsView[KT, VT]: ... | ||
|
||
def isinstance(x: object, t: type) -> bool: ... | ||
|
||
class _Sized(Protocol): | ||
def __len__(self) -> int: ... | ||
|
||
def len(x: _Sized) -> int: ... |
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.
Just wondering, any particular reason not to use the new fixture for all ParamSpec tests? I noticed that a few where missing. Especially between L90 - L550.
Uh oh!
There was an error while loading. Please reload this page.
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.
I used the new fixture in all the tests that broke with the changes made in this PR ;) They mostly broke because
builtins.dict
is undefined intuple.pyi
, but we need it for a lot ofParamSpec
-related tests ifParamSpec.kwargs
is bound todict[str, Any]
.There's no particular reason not to use them in all
ParamSpec
tests -- but I wanted to keep the diff as small as possible, and the remaining tests don't need all the classes included inparamspec.pyi
. (I think it's best to use as minimal a fixture as possible, in most situations, to avoid slowing down the test suite.)