bpo-43908: check_set_special_type_attr() checks Py_TPFLAGS_IMMUTABLET… · python/cpython@6414138 (original) (raw)

`@@ -466,14 +466,16 @@ static PyMemberDef type_members[] = {

`

466

466

`static int

`

467

467

`check_set_special_type_attr(PyTypeObject *type, PyObject *value, const char *name)

`

468

468

`{

`

469

``

`-

if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {

`

``

469

`+

if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {

`

470

470

`PyErr_Format(PyExc_TypeError,

`

471

``

`-

"can't set %s.%s", type->tp_name, name);

`

``

471

`+

"cannot set '%s' attribute of immutable type '%s'",

`

``

472

`+

name, type->tp_name);

`

472

473

`return 0;

`

473

474

` }

`

474

475

`if (!value) {

`

475

476

`PyErr_Format(PyExc_TypeError,

`

476

``

`-

"can't delete %s.%s", type->tp_name, name);

`

``

477

`+

"cannot delete '%s' attribute of immutable type '%s'",

`

``

478

`+

name, type->tp_name);

`

477

479

`return 0;

`

478

480

` }

`

479

481

``

`@@ -978,8 +980,10 @@ type_get_annotations(PyTypeObject *type, void *context)

`

978

980

`static int

`

979

981

`type_set_annotations(PyTypeObject *type, PyObject *value, void *context)

`

980

982

`{

`

981

``

`-

if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {

`

982

``

`-

PyErr_Format(PyExc_TypeError, "can't set attributes of built-in/extension type '%s'", type->tp_name);

`

``

983

`+

if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {

`

``

984

`+

PyErr_Format(PyExc_TypeError,

`

``

985

`+

"cannot set 'annotations' attribute of immutable type '%s'",

`

``

986

`+

type->tp_name);

`

983

987

`return -1;

`

984

988

` }

`

985

989

``

`@@ -3953,8 +3957,8 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)

`

3953

3957

`if (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) {

`

3954

3958

`PyErr_Format(

`

3955

3959

`PyExc_TypeError,

`

3956

``

`-

"can't set attributes of built-in/extension type '%s'",

`

3957

``

`-

type->tp_name);

`

``

3960

`+

"cannot set %R attribute of immutable type '%s'",

`

``

3961

`+

name, type->tp_name);

`

3958

3962

`return -1;

`

3959

3963

` }

`

3960

3964

`if (PyUnicode_Check(name)) {

`