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

Appearance settings

gh-132713: Fix typing.Union[index] race condition #132802

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

Merged
merged 8 commits into from
Apr 23, 2025
Merged
Changes from all commits
Commits
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
29 changes: 19 additions & 10 deletions 29 Objects/unionobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,29 @@ static PyMemberDef union_members[] = {
{0}
};

static PyObject *
union_getitem(PyObject *self, PyObject *item)
// Populate __parameters__ if needed.
static int
union_init_parameters(unionobject *alias)
{
unionobject *alias = (unionobject *)self;
// Populate __parameters__ if needed.
int result = 0;
Py_BEGIN_CRITICAL_SECTION(alias);
if (alias->parameters == NULL) {
alias->parameters = _Py_make_parameters(alias->args);
if (alias->parameters == NULL) {
vstinner marked this conversation as resolved.
Show resolved Hide resolved
return NULL;
result = -1;
}
}
Py_END_CRITICAL_SECTION();
return result;
}

static PyObject *
union_getitem(PyObject *self, PyObject *item)
{
unionobject *alias = (unionobject *)self;
if (union_init_parameters(alias) < 0) {
return NULL;
}

PyObject *newargs = _Py_subs_parameters(self, alias->args, alias->parameters, item);
if (newargs == NULL) {
Expand All @@ -352,11 +364,8 @@ static PyObject *
union_parameters(PyObject *self, void *Py_UNUSED(unused))
{
unionobject *alias = (unionobject *)self;
if (alias->parameters == NULL) {
alias->parameters = _Py_make_parameters(alias->args);
if (alias->parameters == NULL) {
return NULL;
}
if (union_init_parameters(alias) < 0) {
return NULL;
}
return Py_NewRef(alias->parameters);
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.