Skip to content

Double check of PyContextVar_CheckExact in PyContextVar_Set #142873

@sobolevn

Description

@sobolevn

Bug report

This code does checking for PyContextVar_CheckExact twice:

cpython/Python/context.c

Lines 340 to 350 in 1fc3039

PyObject *
PyContextVar_Set(PyObject *ovar, PyObject *val)
{
ENSURE_ContextVar(ovar, NULL)
PyContextVar *var = (PyContextVar *)ovar;
if (!PyContextVar_CheckExact(var)) {
PyErr_SetString(
PyExc_TypeError, "an instance of ContextVar was expected");
return NULL;
}

First in:

cpython/Python/context.c

Lines 28 to 33 in 1fc3039

#define ENSURE_ContextVar(o, err_ret) \
if (!PyContextVar_CheckExact(o)) { \
PyErr_SetString(PyExc_TypeError, \
"an instance of ContextVar was expected"); \
return err_ret; \
}

Then in:

cpython/Python/context.c

Lines 346 to 350 in 1fc3039

if (!PyContextVar_CheckExact(var)) {
PyErr_SetString(
PyExc_TypeError, "an instance of ContextVar was expected");
return NULL;
}

There's no reason to do this.

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions