Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
JelleZijlstra merged 56 commits intopython:mainfromJelleZijlstra:pep696v2
May 3, 2024
Merged
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
JelleZijlstraFeb 29, 2024
828679e
Fix test_ast
JelleZijlstraFeb 29, 2024
d3b472b
new tests
JelleZijlstraFeb 29, 2024
6e467ee
fix test_unparse
JelleZijlstraFeb 29, 2024
fa48580
possible solution
JelleZijlstraMar 1, 2024
49b077b
Can't use the name either
JelleZijlstraMar 1, 2024
5cfd5e2
blurb
JelleZijlstraMar 1, 2024
01b3270
should not have pushed that
JelleZijlstraMar 1, 2024
7a69204
maybe this will compile
JelleZijlstraMar 1, 2024
a265008
Feature version support
JelleZijlstraMar 1, 2024
0c28297
Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstraApr 10, 2024
8aa5b27
default_ -> default_value
JelleZijlstraApr 10, 2024
bdd01bb
ast docs
JelleZijlstraApr 10, 2024
2c28b9a
more docs
JelleZijlstraApr 10, 2024
b0d467f
Fix typevarobject.c
JelleZijlstraApr 10, 2024
d7e91e2
default=<unrepresentable>
JelleZijlstraApr 10, 2024
35226b4
NoneType is immortal
JelleZijlstraApr 10, 2024
2e079ee
Runtime implementation
JelleZijlstraApr 10, 2024
e037052
What's New
JelleZijlstraApr 10, 2024
7b15f11
Document None/NoneType weirdness
JelleZijlstraApr 10, 2024
11bd102
fix doctest
JelleZijlstraApr 11, 2024
c54aeed
Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstraApr 23, 2024
71a348b
Feedback from Alex
JelleZijlstraApr 23, 2024
900cd40
Partial work
JelleZijlstraApr 23, 2024
c13420b
Allow * in TypeVarTuple default
JelleZijlstraApr 23, 2024
8a08c62
Test and fix grammar
JelleZijlstraApr 23, 2024
613159f
Fix TypeVarTuple substitution
JelleZijlstraApr 23, 2024
4e0435e
Two more cases
JelleZijlstraApr 23, 2024
7d54ace
Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstraApr 23, 2024
12581d8
Fix TypeVar substitution
JelleZijlstraApr 23, 2024
2b5a102
Fix ParamSpec
JelleZijlstraApr 23, 2024
a2c48c9
Prohibit default after TypeVarTuple
JelleZijlstraApr 23, 2024
29b9435
Wrap new syntax in run_code()
JelleZijlstraApr 23, 2024
326de17
Silence Ruff
JelleZijlstraApr 23, 2024
6f66775
Fix parameter markup
JelleZijlstraApr 23, 2024
7efa4ce
default_ -> default_value
JelleZijlstraApr 23, 2024
29ad843
Fix errors
JelleZijlstraApr 23, 2024
2c04c14
arguments, not parameters
JelleZijlstraApr 23, 2024
7d4f3fd
Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstraApr 23, 2024
1a14367
Apply suggestions from code review
JelleZijlstraApr 23, 2024
5890d79
regen clinic
JelleZijlstraApr 23, 2024
19a7b48
variadic args for _unpack_args
JelleZijlstraApr 23, 2024
ef0616b
Update Lib/typing.py
JelleZijlstraApr 23, 2024
9d4e842
Update Doc/reference/executionmodel.rst
JelleZijlstraApr 23, 2024
2686b97
Roundtrip tests
JelleZijlstraApr 24, 2024
98d1dec
Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstraApr 28, 2024
fbb6405
Fix doctest
JelleZijlstraApr 28, 2024
e0ccfeb
Add typing.NoDefault as the default for TypeVar's default
JelleZijlstraApr 28, 2024
15aaff9
Apply suggestions from code review
JelleZijlstraApr 28, 2024
86f5aed
Add .has_default() and update docs
JelleZijlstraApr 28, 2024
3e0c0fc
Apply suggestions from code review
JelleZijlstraApr 28, 2024
f5a3d4b
remove trailing space
JelleZijlstraApr 28, 2024
92ea108
Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstraApr 30, 2024
5f6fdfd
Ignore new C globals
JelleZijlstraApr 30, 2024
b3f053c
Merge remote-tracking branch 'upstream/main' into pep696v2
JelleZijlstraMay 3, 2024
8c3e0b4
Fix scoping key
JelleZijlstraMay 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
arguments, not parameters
  • Loading branch information
@JelleZijlstra
JelleZijlstra committedApr 23, 2024
commit2c04c14f9c4292cfff9265e382b60254ee54264c
55 changes: 28 additions & 27 deletionsLib/typing.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -304,30 +304,31 @@ def _collect_parameters(args):
return tuple(parameters)


def _check_generic_specialization(cls,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.
"""
elen = len(cls.__parameters__)
if notelen:
expected_len = len(cls.__parameters__)
if notexpected_len:
raise TypeError(f"{cls} is not a generic class")
alen = len(parameters)
ifalen !=elen:
actual_len = len(arguments)
ifactual_len !=expected_len:
# deal with defaults
if alen < elen:
# since we validate defaults in _collect_type_vars
# or _collect_parameters, we can safely check parameters[alen]
if cls.__parameters__[alen].__default__ is not None:
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().
if cls.__parameters__[actual_len].__default__ is not None:
return

elen -= sum(p.__default__ is not None for p in cls.__parameters__)
expect_val = f"at least {elen}"
expected_len -= sum(p.__default__ is not None for p in cls.__parameters__)
expect_val = f"at least {expected_len}"
else:
expect_val =elen
expect_val =expected_len

raise TypeError(f"Too {'many' ifalen >elen else 'few'} arguments"
f" for {cls}; actual {alen}, expected {expect_val}")
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):
Expand DownExpand Up@@ -1160,52 +1161,52 @@ def _paramspec_prepare_subst(self, alias, args):


@_tp_cache
def _generic_class_getitem(cls,params):
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 `params=int`.
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(params, tuple):
params = (params,)
if not isinstance(args, tuple):
args = (args,)

params = tuple(_type_convert(p) for p inparams)
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 notparams:
if notargs:
raise TypeError(
f"Parameter list to {cls.__qualname__}[...] cannot be empty"
)
if not all(_is_typevar_like(p) for p inparams):
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(params)) != len(params):
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:
params = prepare(cls,params)
_check_generic_specialization(cls,params)
args = prepare(cls,args)
_check_generic_specialization(cls,args)

new_args = []
for param, new_arg in zip(cls.__parameters__,params):
for param, new_arg in zip(cls.__parameters__,args):
if isinstance(param, TypeVarTuple):
new_args.extend(new_arg)
else:
new_args.append(new_arg)
params = tuple(new_args)
args = tuple(new_args)

return _GenericAlias(cls,params)
return _GenericAlias(cls,args)


def _generic_init_subclass(cls, *args, **kwargs):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp