Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-116126: Implement PEP 696#116129
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+1,924 −623
Merged
gh-116126: Implement PEP 696#116129
Changes from1 commit
Commits
Show all changes
56 commits Select commitHold shift + click to select a range
e7ca092 gh-116126: Grammar changes for PEP 696
JelleZijlstra828679e Fix test_ast
JelleZijlstrad3b472b new tests
JelleZijlstra6e467ee fix test_unparse
JelleZijlstrafa48580 possible solution
JelleZijlstra49b077b Can't use the name either
JelleZijlstra5cfd5e2 blurb
JelleZijlstra01b3270 should not have pushed that
JelleZijlstra7a69204 maybe this will compile
JelleZijlstraa265008 Feature version support
JelleZijlstra0c28297 Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstra8aa5b27 default_ -> default_value
JelleZijlstrabdd01bb ast docs
JelleZijlstra2c28b9a more docs
JelleZijlstrab0d467f Fix typevarobject.c
JelleZijlstrad7e91e2 default=<unrepresentable>
JelleZijlstra35226b4 NoneType is immortal
JelleZijlstra2e079ee Runtime implementation
JelleZijlstrae037052 What's New
JelleZijlstra7b15f11 Document None/NoneType weirdness
JelleZijlstra11bd102 fix doctest
JelleZijlstrac54aeed Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstra71a348b Feedback from Alex
JelleZijlstra900cd40 Partial work
JelleZijlstrac13420b Allow * in TypeVarTuple default
JelleZijlstra8a08c62 Test and fix grammar
JelleZijlstra613159f Fix TypeVarTuple substitution
JelleZijlstra4e0435e Two more cases
JelleZijlstra7d54ace Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstra12581d8 Fix TypeVar substitution
JelleZijlstra2b5a102 Fix ParamSpec
JelleZijlstraa2c48c9 Prohibit default after TypeVarTuple
JelleZijlstra29b9435 Wrap new syntax in run_code()
JelleZijlstra326de17 Silence Ruff
JelleZijlstra6f66775 Fix parameter markup
JelleZijlstra7efa4ce default_ -> default_value
JelleZijlstra29ad843 Fix errors
JelleZijlstra2c04c14 arguments, not parameters
JelleZijlstra7d4f3fd Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstra1a14367 Apply suggestions from code review
JelleZijlstra5890d79 regen clinic
JelleZijlstra19a7b48 variadic args for _unpack_args
JelleZijlstraef0616b Update Lib/typing.py
JelleZijlstra9d4e842 Update Doc/reference/executionmodel.rst
JelleZijlstra2686b97 Roundtrip tests
JelleZijlstra98d1dec Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstrafbb6405 Fix doctest
JelleZijlstrae0ccfeb Add typing.NoDefault as the default for TypeVar's default
JelleZijlstra15aaff9 Apply suggestions from code review
JelleZijlstra86f5aed Add .has_default() and update docs
JelleZijlstra3e0c0fc Apply suggestions from code review
JelleZijlstraf5a3d4b remove trailing space
JelleZijlstra92ea108 Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstra5f6fdfd Ignore new C globals
JelleZijlstrab3f053c Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstra8c3e0b4 Fix scoping key
JelleZijlstraFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
arguments, not parameters
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit2c04c14f9c4292cfff9265e382b60254ee54264c
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -304,30 +304,31 @@ def _collect_parameters(args): | ||
| return tuple(parameters) | ||
| def _check_generic_specialization(cls,arguments): | ||
| """Check correct count for parameters of a generic cls (internal helper). | ||
| This gives a nice error message in case of count mismatch. | ||
| """ | ||
| expected_len = len(cls.__parameters__) | ||
| if notexpected_len: | ||
| raise TypeError(f"{cls} is not a generic class") | ||
| actual_len = len(arguments) | ||
| ifactual_len !=expected_len: | ||
| # deal with defaults | ||
| if actual_len < expected_len: | ||
| # If the parameter at actual_len has a default, then all parameters | ||
| # after it must also have one, because we validated as much in | ||
| # _collect_parameters(). | ||
JelleZijlstra marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if cls.__parameters__[actual_len].__default__ is not None: | ||
| return | ||
| expected_len -= sum(p.__default__ is not None for p in cls.__parameters__) | ||
| expect_val = f"at least {expected_len}" | ||
| else: | ||
| expect_val =expected_len | ||
| raise TypeError(f"Too {'many' ifactual_len >expected_len else 'few'} arguments" | ||
| f" for {cls}; actual {actual_len}, expected {expect_val}") | ||
| def _unpack_args(args): | ||
| @@ -1160,52 +1161,52 @@ def _paramspec_prepare_subst(self, alias, args): | ||
| @_tp_cache | ||
| def _generic_class_getitem(cls,args): | ||
| """Parameterizes a generic class. | ||
| At least, parameterizing a generic class is the *main* thing this method | ||
| does. For example, for some generic class `Foo`, this is called when we | ||
| do `Foo[int]` - there, with `cls=Foo` and `args=int`. | ||
| However, note that this method is also called when defining generic | ||
| classes in the first place with `class Foo(Generic[T]): ...`. | ||
| """ | ||
| if not isinstance(args, tuple): | ||
| args = (args,) | ||
| args = tuple(_type_convert(p) for p inargs) | ||
| is_generic_or_protocol = cls in (Generic, Protocol) | ||
| if is_generic_or_protocol: | ||
| # Generic and Protocol can only be subscripted with unique type variables. | ||
| if notargs: | ||
| raise TypeError( | ||
| f"Parameter list to {cls.__qualname__}[...] cannot be empty" | ||
| ) | ||
| if not all(_is_typevar_like(p) for p inargs): | ||
| raise TypeError( | ||
| f"Parameters to {cls.__name__}[...] must all be type variables " | ||
| f"or parameter specification variables.") | ||
| if len(set(args)) != len(args): | ||
| raise TypeError( | ||
| f"Parameters to {cls.__name__}[...] must all be unique") | ||
| else: | ||
| # Subscripting a regular Generic subclass. | ||
| for param in cls.__parameters__: | ||
| prepare = getattr(param, '__typing_prepare_subst__', None) | ||
| if prepare is not None: | ||
| args = prepare(cls,args) | ||
| _check_generic_specialization(cls,args) | ||
| new_args = [] | ||
| for param, new_arg in zip(cls.__parameters__,args): | ||
| if isinstance(param, TypeVarTuple): | ||
| new_args.extend(new_arg) | ||
| else: | ||
| new_args.append(new_arg) | ||
| args = tuple(new_args) | ||
| return _GenericAlias(cls,args) | ||
| def _generic_init_subclass(cls, *args, **kwargs): | ||
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.