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-103763: Implement PEP 695#103764

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 232 commits intopython:mainfromJelleZijlstra:tvobject
May 16, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
232 commits
Select commitHold shift + click to select a range
9c8cd71
Moved portions of earlier prototype into latest main CPython branch. …
msfterictrautApr 9, 2023
609ac0d
Run Tools/build/generate_global_objects.py
JelleZijlstraApr 13, 2023
7a5e457
Basic C implementation of TypeVar, TypeVarTuple, ParamSpec
JelleZijlstraApr 13, 2023
1e0b74c
fix TypeVar signature
JelleZijlstraApr 13, 2023
2a5023a
fix TypeVar argument parsing
JelleZijlstraApr 13, 2023
1bc8574
ParamSpecArgs/Kwargs
JelleZijlstraApr 14, 2023
ed42796
make typing importable
JelleZijlstraApr 14, 2023
d06f43d
Add some things
JelleZijlstraApr 14, 2023
830b36a
Updated unit tests to reflect the latest PEP 695 spec.
msfterictrautApr 14, 2023
b6bf2bc
Merge remote-tracking branch 'erictraut/type_param_syntax4' into tvob…
JelleZijlstraApr 15, 2023
6bb4795
Make *Ts work
JelleZijlstraApr 15, 2023
c7c1618
Just call typing.py
JelleZijlstraApr 15, 2023
772920f
attempt at pickling
JelleZijlstraApr 15, 2023
6ff6f5a
better approach
JelleZijlstraApr 15, 2023
9fdf373
fix a few tests and refcount bugs
JelleZijlstraApr 15, 2023
f7c513d
Use Name expr for TypeAlias
cdce8pApr 16, 2023
1d7b035
Add ast optimizer for typeparam
cdce8pApr 16, 2023
85a4409
Use Name expr for TypeParameter
cdce8pApr 16, 2023
55d0fd9
Revert AST changes for TypeParams
cdce8pApr 17, 2023
618e173
Merge pull request #7 from cdce8p/eric-ast-changes
erictrautApr 18, 2023
bef978f
broken compiler before merge
JelleZijlstraApr 18, 2023
3cd026a
Merge remote-tracking branch 'erictraut/type_param_syntax4' into tvob…
JelleZijlstraApr 18, 2023
b12663d
Works for functions
JelleZijlstraApr 18, 2023
bb9c43c
fall back to normal scope
JelleZijlstraApr 18, 2023
037ddfa
does not exactly work
JelleZijlstraApr 19, 2023
a62f0c2
commit before new approach
JelleZijlstraApr 21, 2023
9c7a153
New approach
JelleZijlstraApr 21, 2023
aa8ea68
correctly make it a cellvar
JelleZijlstraApr 21, 2023
ab6b718
Now it works
JelleZijlstraApr 21, 2023
dba4293
fix defaults
JelleZijlstraApr 21, 2023
e36c5f5
undo some unnecessary changes
JelleZijlstraApr 21, 2023
21e1b1a
support async def
JelleZijlstraApr 21, 2023
8505134
start class support
JelleZijlstraApr 21, 2023
338b978
detect duplicate type params
JelleZijlstraApr 21, 2023
04bc911
clean up some whitespace
JelleZijlstraApr 22, 2023
521bd81
Improve some tests
JelleZijlstraApr 22, 2023
f2d91b0
No runtime error there
JelleZijlstraApr 22, 2023
ccf68d9
actually generate a typevar
JelleZijlstraApr 22, 2023
6159d75
refactor typeparam blocks
JelleZijlstraApr 22, 2023
d9c0d90
Fix nested class scopes (functions)
JelleZijlstraApr 22, 2023
d26b82a
fix it in classes too
JelleZijlstraApr 22, 2023
423d2de
Support bounds
JelleZijlstraApr 22, 2023
fdd8877
Use dummy class to get TypeVar-like types
JelleZijlstraApr 22, 2023
2461ed5
fix typo in test
JelleZijlstraApr 22, 2023
e9a196f
Add union support to TypeVar (and ParamSpec, somewhat dubiously)
JelleZijlstraApr 22, 2023
536cf13
add function.__type_variables__
JelleZijlstraApr 23, 2023
c0b04e3
Generic work
JelleZijlstraApr 23, 2023
59e6fa0
Use _Py_DECLARE_STR
JelleZijlstraApr 23, 2023
5521c7d
Support inheriting from Generic
JelleZijlstraApr 23, 2023
b9d8fbb
Fix up qualnames
JelleZijlstraApr 23, 2023
f3340c2
Update the magic number, rearrange typing.py accordingly
JelleZijlstraApr 23, 2023
b5de372
fix missing initialization
JelleZijlstraApr 23, 2023
fa81c01
set __type_variables__ on classes
JelleZijlstraApr 23, 2023
7aeee08
Add docs to typevarobject.c
JelleZijlstraApr 23, 2023
a7e6bcb
drop Python implementations of Generic, TypeVar, etc.
JelleZijlstraApr 23, 2023
fe84458
fix Generic
JelleZijlstraApr 23, 2023
34c024d
make generics instantiable
JelleZijlstraApr 23, 2023
d9ec56e
fix NamedTuple
JelleZijlstraApr 23, 2023
6ab8b1e
fix some tests
JelleZijlstraApr 23, 2023
d916974
one more
JelleZijlstraApr 23, 2023
b38dea4
Use a heap type for Generic
JelleZijlstraApr 24, 2023
8991bb1
Better way to set __type_variables__ in the class
JelleZijlstraApr 24, 2023
c3f520a
Fix TypeVar | "ForwardRef"
JelleZijlstraApr 24, 2023
e668ed8
Make ParamSpecArgs and Kwargs not subclassable
JelleZijlstraApr 24, 2023
2b844f4
Correctly unpack TypeVarTuple
JelleZijlstraApr 24, 2023
47d24d9
Add support for type aliases (but not for computing the value)
JelleZijlstraApr 24, 2023
8ad0b5b
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 24, 2023
6312d7b
fix merge
JelleZijlstraApr 24, 2023
48e23b0
Avoid complicating compile_call_helper
JelleZijlstraApr 24, 2023
dec31ae
Apparently it is a length-0 list if there are no typeparams, not NULL
JelleZijlstraApr 24, 2023
062999c
Fix GC for TypeAlias
JelleZijlstraApr 24, 2023
9147a4a
fix warnings
JelleZijlstraApr 24, 2023
1b043c8
Add to globals-to-fix
JelleZijlstraApr 24, 2023
16cb6a5
Add to _freeze_module.vcxproj
JelleZijlstraApr 24, 2023
1bdfb75
Use heap types, fixing pickling
JelleZijlstraApr 24, 2023
308c7c1
Fix GC
JelleZijlstraApr 24, 2023
ff22d22
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 24, 2023
c4ce394
Self-review
JelleZijlstraApr 24, 2023
f02199f
It's supposed to be called TypeAliasType
JelleZijlstraApr 25, 2023
3fe019b
Allow evaluating TypeAlias
JelleZijlstraApr 25, 2023
737d96a
Support __or__ on type aliases
JelleZijlstraApr 25, 2023
6fe9476
fix | and subscripting on TypeAliasType
JelleZijlstraApr 25, 2023
80a9efb
Test fixes and new tests
JelleZijlstraApr 25, 2023
21b3aec
Add syntax error for nonlocal as specified by the PEP
JelleZijlstraApr 25, 2023
30487a5
Implement TypeAlias repr
JelleZijlstraApr 25, 2023
1575c66
__type_variables__ -> __type_params__
JelleZijlstraApr 25, 2023
a6045f0
Remove POP_NULL
JelleZijlstraApr 25, 2023
2c8b4f1
Lazily evaluate TypeVar bounds/constraints
JelleZijlstraApr 25, 2023
66851e6
Add NEWS
JelleZijlstraApr 25, 2023
be059c1
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 25, 2023
ac7f722
Disallow yield/yield from/await/walrus
JelleZijlstraApr 25, 2023
0f70925
fix doctests
JelleZijlstraApr 25, 2023
e17c3b0
Stop altering the execution environment
JelleZijlstraApr 25, 2023
45696ae
Disallow walrus/yield while evaluating generics
JelleZijlstraApr 25, 2023
02e0a8a
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 25, 2023
7a8fc14
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 25, 2023
7195162
regen all, minor quality improvements
JelleZijlstraApr 25, 2023
5fbd4d5
fix leaked ref to the TypeAlias type
JelleZijlstraApr 25, 2023
f86be9c
Fix another leak
JelleZijlstraApr 25, 2023
77b3807
Deallocate Generic correctly
JelleZijlstraApr 25, 2023
f448248
Avoid a new funcflags
JelleZijlstraApr 25, 2023
d32bc61
Fix missing INCREF
JelleZijlstraApr 25, 2023
27a8a4c
Fix repr() for recursive type aliases
JelleZijlstraApr 25, 2023
44b9222
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 26, 2023
445a39b
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 26, 2023
7fa37b4
Fix refleak in ParamSpecArgs/Kwargs
JelleZijlstraApr 26, 2023
880f066
Add tp_clear methods
JelleZijlstraApr 26, 2023
3d8e24e
regen-global-objects
JelleZijlstraApr 26, 2023
74c1a0d
Apparently not
JelleZijlstraApr 26, 2023
d5b86c5
Merge branch 'main' into tvobject
JelleZijlstraApr 26, 2023
3b6098d
Add lookahead to grammar
JelleZijlstraApr 26, 2023
9632c02
First try! It fails! James Powell rules apply.
larryhastingsApr 26, 2023
8a0ecb7
simplify the intrinsic
JelleZijlstraApr 26, 2023
0bb175a
Changed strategy, func_class_dict and *_CLASS_DICT.
larryhastingsApr 26, 2023
5e4ec0e
Update comment on new magic number.
larryhastingsApr 26, 2023
12d3004
Cleanup leftover gunk from previous approach.
larryhastingsApr 26, 2023
6c3f65a
Add class.__globals__, fix refcnt bugs. Thx Jelle!
larryhastingsApr 26, 2023
84a00ce
LOAD_CLASS_DICT also checks globals. Thx Jelle!
larryhastingsApr 26, 2023
e0acb87
Make LOAD_CLASS_DICT also look in the global namespace and rename it …
JelleZijlstraApr 26, 2023
d77c4fb
Merge branch 'loadclass' into tvobject
JelleZijlstraApr 26, 2023
ea66c7c
Use INTRINSIC_SET_CLASS_DICT
JelleZijlstraApr 27, 2023
b314a3f
Correctly handle class namespaces in TV bounds
JelleZijlstraApr 27, 2023
2e913ca
Same for type aliases
JelleZijlstraApr 27, 2023
394d128
Add test cases
JelleZijlstraApr 27, 2023
bd49622
Handle name mangling
JelleZijlstraApr 27, 2023
bf45a8e
I don't need __globals__ and it causes a lot of failures
JelleZijlstraApr 27, 2023
ce7fe9c
Fix another test
JelleZijlstraApr 27, 2023
e5a6c21
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 27, 2023
96324a5
Extend NEWS entry, give credit to Larry
JelleZijlstraApr 27, 2023
fd0f7b4
Fix GC tracking in error conditions
JelleZijlstraApr 27, 2023
e784da1
More error paths
JelleZijlstraApr 27, 2023
72fc40c
Fix the NEWS?
JelleZijlstraApr 27, 2023
4b6a815
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 27, 2023
93a4552
Can't have multi-line bulleted lists in NEWS
JelleZijlstraApr 27, 2023
b36b7af
More test cases, remove redundant comment
JelleZijlstraApr 27, 2023
a85fb6c
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 27, 2023
6454026
Add LOAD_CLASSDICT_OR_DEREF
JelleZijlstraApr 27, 2023
21667d9
Remove outdated comment
JelleZijlstraApr 27, 2023
e65d668
Add helper function to tests
JelleZijlstraApr 27, 2023
e0a0b04
Expose TypeVar and friends through _typing
JelleZijlstraApr 27, 2023
d5c44f5
Remove unnecessary symtable entry
JelleZijlstraApr 27, 2023
ce6a990
Rename variable for clarity
JelleZijlstraApr 27, 2023
2fc9cc7
fix shadowed test
JelleZijlstraApr 27, 2023
3f71911
Use run_code in test_type_aliases too
JelleZijlstraApr 27, 2023
0891a61
Update NEWS
JelleZijlstraApr 27, 2023
78a9ba2
type is a soft keyword too
JelleZijlstraApr 27, 2023
c0b45e1
add to test_ast
JelleZijlstraApr 27, 2023
16a037f
Move functions closer together
JelleZijlstraApr 27, 2023
c5d9378
try this way
JelleZijlstraApr 28, 2023
0399ed4
comments
JelleZijlstraApr 28, 2023
782fc35
Maybe this
JelleZijlstraApr 28, 2023
a092896
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 28, 2023
0241da5
avoid special qualname handling
JelleZijlstraApr 28, 2023
5b3a204
Fix opcode classification
JelleZijlstraApr 28, 2023
78f3f4b
Fix qualname test
JelleZijlstraApr 28, 2023
9d3177b
Harmonize implementation of the two intrinsics
JelleZijlstraApr 28, 2023
c52179c
Simplify LOAD_LOCALS at the cost of compiler complexity
JelleZijlstraApr 28, 2023
d0fa718
fix WASM
JelleZijlstraApr 29, 2023
f0936de
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 29, 2023
5259096
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraApr 29, 2023
c3d6464
Fix compiler warning
JelleZijlstraApr 29, 2023
f580583
use check_syntax_error
JelleZijlstraApr 30, 2023
17c8060
Better error messages for illegal bounds/constraints
JelleZijlstraApr 30, 2023
f4ea500
Add CHECK_VERSION for type param lists
JelleZijlstraApr 30, 2023
43bcd02
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 3, 2023
827b9e5
Test that super() works correctly within a hidden function
JelleZijlstraMay 3, 2023
71cef78
Use a __classdict__ cell to store the class namespace (#3)
JelleZijlstraMay 7, 2023
80ffbf3
Merge branch 'main' into tvobject
JelleZijlstraMay 7, 2023
e786382
Fix a test
JelleZijlstraMay 7, 2023
2a8f0ef
Remove stray function declarations
JelleZijlstraMay 9, 2023
967f100
More thorough tests
JelleZijlstraMay 9, 2023
4cbbd24
More CR on tests
JelleZijlstraMay 9, 2023
8dfb93d
Update comment
JelleZijlstraMay 9, 2023
43f0270
Real error for type_check
JelleZijlstraMay 9, 2023
0b35c6c
Use vectorcall
JelleZijlstraMay 9, 2023
a2f3c75
Small fixes to typevarobject.c
JelleZijlstraMay 9, 2023
c51b9fc
mod, not mad
JelleZijlstraMay 9, 2023
047abba
Use dict_add_o for class cells
JelleZijlstraMay 9, 2023
51a4655
Small compiler fixes
JelleZijlstraMay 9, 2023
5e68cd8
Refactor compiler_function for correct scope handling
JelleZijlstraMay 9, 2023
3b63b76
Same for classes
JelleZijlstraMay 9, 2023
281f575
And for type aliases
JelleZijlstraMay 9, 2023
a3cd2e7
fixup
JelleZijlstraMay 9, 2023
a4f6076
Remove unnecessary LOAD_LOCALS
JelleZijlstraMay 9, 2023
88ac5dc
Remove .type_params for functions
JelleZijlstraMay 9, 2023
32fc89c
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 9, 2023
02f1fca
Forgot one regen
JelleZijlstraMay 9, 2023
249ca43
Simplify bytecode as suggested by Carl
JelleZijlstraMay 9, 2023
645b08b
Add some test cases for unusual calls
JelleZijlstraMay 9, 2023
17c30f6
Avoid compiler_nameop change
JelleZijlstraMay 9, 2023
0067e00
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 10, 2023
39ace71
Rip out making bound a set
JelleZijlstraMay 10, 2023
a1c59f7
New solution for nonlocal
JelleZijlstraMay 10, 2023
f7e6219
Simplify TypeAliasType.__repr__
JelleZijlstraMay 10, 2023
8f54b02
Remove bogus assertions
JelleZijlstraMay 10, 2023
bb2df61
Remove redundant condition
JelleZijlstraMay 10, 2023
fdf65ad
Use compiler_addop_o
JelleZijlstraMay 10, 2023
4fecf7d
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 10, 2023
f8406ce
Undo unnecessary bracing changes
JelleZijlstraMay 11, 2023
fd4fe5c
Separate out and expand nonlocal tests
JelleZijlstraMay 11, 2023
0b94580
Add comments to the enum
JelleZijlstraMay 11, 2023
e952d61
Some more tests and consistent naming
JelleZijlstraMay 11, 2023
785dd45
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 11, 2023
be70e3c
Use _PyST_IsFunctionLike in comprehension inlining code
JelleZijlstraMay 11, 2023
92c29e7
Simplify Generic creation
JelleZijlstraMay 11, 2023
529c74d
Public constructor for TypeAlias
JelleZijlstraMay 12, 2023
531fcf7
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 12, 2023
497e22a
regen opcode_targets.h
JelleZijlstraMay 12, 2023
bfb5ac0
Add test now that it no longer crashes
JelleZijlstraMay 12, 2023
a1be61d
Fix one refleak
JelleZijlstraMay 12, 2023
1e9273c
Fix the other refleak
JelleZijlstraMay 12, 2023
bc37579
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 12, 2023
3817ab4
Fix one more refleak
JelleZijlstraMay 12, 2023
f2a9393
Remove unrelated change
JelleZijlstraMay 12, 2023
4f1223e
remove stray raw assert
JelleZijlstraMay 12, 2023
d490251
Merge branch 'main' into tvobject
JelleZijlstraMay 12, 2023
33f4c12
Update typevarobject.c: use Py_RETURN_NONE
JelleZijlstraMay 12, 2023
b9f4540
Review feedback
JelleZijlstraMay 12, 2023
a64922f
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 12, 2023
8a783b3
Update Lib/test/support/__init__.py
JelleZijlstraMay 12, 2023
9e6658a
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 13, 2023
0aad1f4
Use PyObject for TypeVar etc. names
JelleZijlstraMay 14, 2023
a22a08f
Reorganize compiler opcodes; no more LOAD_CLASSDEREF
JelleZijlstraMay 14, 2023
1328c75
Merge branch 'main' into tvobject
JelleZijlstraMay 14, 2023
7d6016e
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 14, 2023
1401209
Fix another class scoping oddity
JelleZijlstraMay 14, 2023
e049f5a
Make test still succeed under PEP 649
JelleZijlstraMay 14, 2023
c4d9ec4
Fix bug with explicit global in class scope; rename flag for clarity
JelleZijlstraMay 14, 2023
b93f85e
Fix more similar cases
JelleZijlstraMay 14, 2023
f412f49
Merge remote-tracking branch 'upstream/main' into tvobject
JelleZijlstraMay 15, 2023
d4e72a5
A few more tests
JelleZijlstraMay 15, 2023
08d931c
Remove redundant function
JelleZijlstraMay 15, 2023
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
3 changes: 3 additions & 0 deletionsDoc/library/ast.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1724,6 +1724,7 @@ Function and class definitions
body=[
FunctionDef(
name='f',
typeparams=[],
args=arguments(
posonlyargs=[],
args=[
Expand DownExpand Up@@ -1847,6 +1848,7 @@ Function and class definitions
body=[
ClassDef(
name='Foo',
typeparams=[],
bases=[
Name(id='base1', ctx=Load()),
Name(id='base2', ctx=Load())],
Expand DownExpand Up@@ -1885,6 +1887,7 @@ Async and await
body=[
AsyncFunctionDef(
name='f',
typeparams=[],
args=arguments(
posonlyargs=[],
args=[],
Expand Down
46 changes: 40 additions & 6 deletionsGrammar/python.gram
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,6 +112,7 @@ simple_stmts[asdl_stmt_seq*]:
# will throw a SyntaxError.
simple_stmt[stmt_ty] (memo):
| assignment
| &"type" type_alias
| e=star_expressions { _PyAST_Expr(e, EXTRA) }
| &'return' return_stmt
| &('import' | 'from') import_stmt
Expand DownExpand Up@@ -252,8 +253,8 @@ class_def[stmt_ty]:

class_def_raw[stmt_ty]:
| invalid_class_def_raw
| 'class' a=NAME b=['(' z=[arguments] ')' { z }] ':' c=block {
_PyAST_ClassDef(a->v.Name.id,
| 'class' a=NAMEt=[type_params]b=['(' z=[arguments] ')' { z }] ':' c=block {
_PyAST_ClassDef(a->v.Name.id, t,
(b) ? ((expr_ty) b)->v.Call.args : NULL,
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
c, NULL, EXTRA) }
Expand All@@ -267,16 +268,16 @@ function_def[stmt_ty]:

function_def_raw[stmt_ty]:
| invalid_def_raw
| 'def' n=NAME &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
_PyAST_FunctionDef(n->v.Name.id,
| 'def' n=NAMEt=[type_params]&&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
_PyAST_FunctionDef(n->v.Name.id, t,
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
| ASYNC 'def' n=NAME &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
| ASYNC 'def' n=NAMEt=[type_params]&&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
CHECK_VERSION(
stmt_ty,
5,
"Async functions are",
_PyAST_AsyncFunctionDef(n->v.Name.id,
_PyAST_AsyncFunctionDef(n->v.Name.id, t,
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA)
) }
Expand DownExpand Up@@ -628,6 +629,39 @@ keyword_patterns[asdl_seq*]:
keyword_pattern[KeyPatternPair*]:
| arg=NAME '=' value=pattern { _PyPegen_key_pattern_pair(p, arg, value) }

# Type statement
# ---------------

type_alias[stmt_ty]:
| "type" n=NAME t=[type_params] '=' b=expression {
CHECK_VERSION(stmt_ty, 12, "Type statement is",
_PyAST_TypeAlias(CHECK(expr_ty, _PyPegen_set_expr_context(p, n, Store)), t, b, EXTRA)) }

# Type parameter declaration
# --------------------------

type_params[asdl_typeparam_seq*]: '[' t=type_param_seq ']' {
CHECK_VERSION(asdl_typeparam_seq *, 12, "Type parameter lists are", t) }

type_param_seq[asdl_typeparam_seq*]: a[asdl_typeparam_seq*]=','.type_param+ [','] { a }

type_param[typeparam_ty] (memo):
| a=NAME b=[type_param_bound] { _PyAST_TypeVar(a->v.Name.id, b, EXTRA) }
| '*' a=NAME colon=":" e=expression {
RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
? "cannot use constraints with TypeVarTuple"
: "cannot use bound with TypeVarTuple")
}
| '*' a=NAME { _PyAST_TypeVarTuple(a->v.Name.id, EXTRA) }
| '**' a=NAME colon=":" e=expression {
RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
? "cannot use constraints with ParamSpec"
: "cannot use bound with ParamSpec")
}
| '**' a=NAME { _PyAST_ParamSpec(a->v.Name.id, EXTRA) }

type_param_bound[expr_ty]: ":" e=expression { e }

# EXPRESSIONS
# -----------

Expand Down
1 change: 1 addition & 0 deletionsInclude/cpython/funcobject.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,6 +41,7 @@ typedef struct {
PyObject *func_weakreflist; /* List of weak references */
PyObject *func_module; /* The __module__ attribute, can be anything */
PyObject *func_annotations; /* Annotations, a dict or NULL */
PyObject *func_typeparams; /* Tuple of active type variables or NULL */
vectorcallfunc vectorcall;
/* Version number for use by specializer.
* Can set to non-zero when we want to specialize.
Expand Down
97 changes: 76 additions & 21 deletionsInclude/internal/pycore_ast.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

7 changes: 7 additions & 0 deletionsInclude/internal/pycore_ast_state.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 2 additions & 0 deletionsInclude/internal/pycore_function.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@ struct _py_func_state {
extern PyFunctionObject* _PyFunction_FromConstructor(PyFrameConstructor *constr);

extern uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
extern PyObject *_Py_set_function_type_params(
PyThreadState* unused, PyObject *func, PyObject *type_params);

#ifdef __cplusplus
}
Expand Down
8 changes: 8 additions & 0 deletionsInclude/internal/pycore_global_objects.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,14 @@ struct _Py_interp_cached_objects {
PyObject *type_slots_pname;
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];

/* TypeVar and related types */
PyTypeObject *generic_type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why are all these classes stored on the interpreter?
Can't they be made static and shareable?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Generic needs to be used with multiple inheritance; when I used it with static types that didn't work. If you feel strongly that we need static types I can try again.

Also, thanks for the review! I'll probably not have time to push code changes until tonight, but will post some replies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Generic needs to be used with multiple inheritance; when I used it with static types that didn't work.

That is unfortunate. I do think they should be static classes.
However, if we need to fix how inheritance is implemented first, then no need to do it in this PR.

Can you remember and summarize what the problem was?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As I recall, it just didn't work; I got errors from fairly normal usage likeclass X[T](Base): (which needs to double-inherit from Base and Generic).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Any recollection as to what the error messages were?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No, sorry. I can try it out tonight.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I actually misremembered; the failures were a bit less basic: they had to do with the inheritance of__new__. I went back to commitb38dea4, before I made Generic a heap type. There were several test failures intest_typing:

A heap type allowed me to simply omit__new__ and have it be inherited like a normal Python class. With a static type withouttp_new, the class would not be instantiable, and if I had it set toPyType_GenericNew,super().__new__ wouldn't be called correctly.

There were also some issues with pickling, but those should have been fixable.

PyTypeObject *typevar_type;
PyTypeObject *typevartuple_type;
PyTypeObject *paramspec_type;
PyTypeObject *paramspecargs_type;
PyTypeObject *paramspeckwargs_type;
PyTypeObject *typealias_type;
};

#define _Py_INTERP_STATIC_OBJECT(interp, NAME) \
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp