[New-bugs-announce] [issue37002] PyType_FromSpec can't create immutable types

Dino Viehland report at bugs.python.org
Tue May 21 17:31:10 EDT 2019


New submission from Dino Viehland <dinoviehland at gmail.com>:

This is another catch of using PyType_FromSpec (similar to  https://bugs.python.org/issue26979 but also completely different).

Because PyType_FromSpec produces a heap type it gets the Py_TPFLAGS_HEAPTYPE flag set on the newly produced type.  To enforce the immutability of built-in types type_setattro checks this flag.  Therefore these types end up being mutable, e.g:

import _ssl
_ssl.SSLError.x = 42

In addition to not providing parity for replacing PyType_Ready in the stable API, it also means that this could presumably bleed across sub-interpreters or just provide surprising and bad results.

----------
components: Interpreter Core
messages: 343100
nosy: dino.viehland, eric.snow, vstinner
priority: normal
severity: normal
status: open
title: PyType_FromSpec can't create immutable types
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37002>
_______________________________________


More information about the New-bugs-announce mailing list