-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-126085: Add tp_iter
to TypeAliasType to allow star unpacking
#127981
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
Changes from 9 commits
e2e6bdb
982737c
e8674d7
4ffeefc
6674aa1
d42645f
03744a6
f605921
186dc48
dcb1b7b
3607006
3597b66
ab53431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
:class:`typing.TypeAliasType` now supports star unpacking. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// TypeVar, TypeVarTuple, and ParamSpec | ||
// TypeVar, TypeVarTuple, TypeAlias and ParamSpec | ||
tomasr8 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
#include "Python.h" | ||
#include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK, PyAnnotateFormat | ||
#include "pycore_typevarobject.h" | ||
|
@@ -59,6 +59,9 @@ typedef struct { | |
|
||
#include "clinic/typevarobject.c.h" | ||
|
||
#define typevartuple_iter unpack_iter | ||
|
||
#define typealias_iter unpack_iter | ||
|
||
/* NoDefault is a marker object to indicate that a parameter has no default. */ | ||
|
||
static PyObject * | ||
|
@@ -385,7 +388,7 @@ caller(void) | |
} | ||
|
||
static PyObject * | ||
typevartuple_unpack(PyObject *tvt) | ||
unpack(PyObject *self) | ||
{ | ||
PyObject *typing = PyImport_ImportModule("typing"); | ||
if (typing == NULL) { | ||
|
@@ -396,7 +399,7 @@ typevartuple_unpack(PyObject *tvt) | |
Py_DECREF(typing); | ||
return NULL; | ||
} | ||
PyObject *unpacked = PyObject_GetItem(unpack, tvt); | ||
PyObject *unpacked = PyObject_GetItem(unpack, self); | ||
Py_DECREF(typing); | ||
Py_DECREF(unpack); | ||
return unpacked; | ||
|
@@ -431,7 +434,7 @@ unpack_typevartuples(PyObject *params) | |
for (Py_ssize_t i = 0; i < n; i++) { | ||
PyObject *param = PyTuple_GET_ITEM(params, i); | ||
if (Py_IS_TYPE(param, tp)) { | ||
PyObject *unpacked = typevartuple_unpack(param); | ||
PyObject *unpacked = unpack(param); | ||
if (unpacked == NULL) { | ||
Py_DECREF(new_params); | ||
return NULL; | ||
|
@@ -1505,9 +1508,9 @@ typevartuple_dealloc(PyObject *self) | |
} | ||
|
||
static PyObject * | ||
typevartuple_iter(PyObject *self) | ||
unpack_iter(PyObject *self) | ||
{ | ||
PyObject *unpacked = typevartuple_unpack(self); | ||
PyObject *unpacked = unpack(self); | ||
if (unpacked == NULL) { | ||
return NULL; | ||
} | ||
|
@@ -2134,6 +2137,7 @@ PyTypeObject _PyTypeAlias_Type = { | |
.tp_new = typealias_new, | ||
.tp_free = PyObject_GC_Del, | ||
.tp_traverse = (traverseproc)typealias_traverse, | ||
.tp_iter = typealias_iter, | ||
.tp_clear = (inquiry)typealias_clear, | ||
.tp_repr = typealias_repr, | ||
.tp_as_number = &typealias_as_number, | ||
|
Uh oh!
There was an error while loading. Please reload this page.