diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2023-05-16 03:36:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 03:36:23 (GMT) |
commit | 24d8b88420b81fc60aeb0cbcacef1e72d633824a (patch) | |
tree | 1b06e157ddc7d1066fd41a28d2c27270ccf2e278 /Modules | |
parent | fdafdc235e74f2f4fedc1f745bf8b90141daa162 (diff) | |
download | cpython-24d8b88420b81fc60aeb0cbcacef1e72d633824a.zip cpython-24d8b88420b81fc60aeb0cbcacef1e72d633824a.tar.gz cpython-24d8b88420b81fc60aeb0cbcacef1e72d633824a.tar.bz2 |
gh-103763: Implement PEP 695 (#103764)
This implements PEP 695, Type Parameter Syntax. It adds support for:
- Generic functions (def func[T](): ...)
- Generic classes (class X[T](): ...)
- Type aliases (type X = ...)
- New scoping when the new syntax is used within a class body
- Compiler and interpreter changes to support the new syntax and scoping rules
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Eric Traut <eric@traut.com>
Co-authored-by: Larry Hastings <larry@hastings.org>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/Setup.bootstrap.in | 1 | ||||
-rw-r--r-- | Modules/Setup.stdlib.in | 1 | ||||
-rw-r--r-- | Modules/_typingmodule.c | 28 |
3 files changed, 29 insertions, 1 deletions
diff --git a/Modules/Setup.bootstrap.in b/Modules/Setup.bootstrap.in index e3e9b96..8ef0f20 100644 --- a/Modules/Setup.bootstrap.in +++ b/Modules/Setup.bootstrap.in @@ -21,6 +21,7 @@ itertools itertoolsmodule.c _sre _sre/sre.c _thread _threadmodule.c time timemodule.c +_typing _typingmodule.c _weakref _weakref.c # commonly used core modules diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index 95409d4..6db567d 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -41,7 +41,6 @@ @MODULE__QUEUE_TRUE@_queue _queuemodule.c @MODULE__RANDOM_TRUE@_random _randommodule.c @MODULE__STRUCT_TRUE@_struct _struct.c -@MODULE__TYPING_TRUE@_typing _typingmodule.c @MODULE__XXSUBINTERPRETERS_TRUE@_xxsubinterpreters _xxsubinterpretersmodule.c @MODULE__XXINTERPCHANNELS_TRUE@_xxinterpchannels _xxinterpchannelsmodule.c @MODULE__ZONEINFO_TRUE@_zoneinfo _zoneinfo.c diff --git a/Modules/_typingmodule.c b/Modules/_typingmodule.c index 6428637..ed2999c 100644 --- a/Modules/_typingmodule.c +++ b/Modules/_typingmodule.c @@ -1,6 +1,11 @@ /* typing accelerator C extension: _typing module. */ +#ifndef Py_BUILD_CORE +#define Py_BUILD_CORE +#endif + #include "Python.h" +#include "internal/pycore_interp.h" #include "clinic/_typingmodule.c.h" /*[clinic input] @@ -35,7 +40,30 @@ static PyMethodDef typing_methods[] = { PyDoc_STRVAR(typing_doc, "Accelerators for the typing module.\n"); +static int +_typing_exec(PyObject *m) +{ + PyInterpreterState *interp = PyInterpreterState_Get(); + +#define EXPORT_TYPE(name, typename) \ + if (PyModule_AddObjectRef(m, name, \ + (PyObject *)interp->cached_objects.typename) < 0) { \ + return -1; \ + } + + EXPORT_TYPE("TypeVar", typevar_type); + EXPORT_TYPE("TypeVarTuple", typevartuple_type); + EXPORT_TYPE("ParamSpec", paramspec_type); + EXPORT_TYPE("ParamSpecArgs", paramspecargs_type); + EXPORT_TYPE("ParamSpecKwargs", paramspeckwargs_type); + EXPORT_TYPE("TypeAliasType", typealias_type); + EXPORT_TYPE("Generic", generic_type); +#undef EXPORT_TYPE + return 0; +} + static struct PyModuleDef_Slot _typingmodule_slots[] = { + {Py_mod_exec, _typing_exec}, {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, {0, NULL} }; |