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