List of built-in types converted to heap types

Ref. bpo-43908: here’s a list of stdlib types that have been converted from static types (allocated on the stack) to heap allocated types.

Each type has a Markdown checkbox, for convenience when marking types that should be immutable. Commits are listed chronologically. For readability, I’ve split it up in chunks; if you prefer one large list instead, I’ll remove the [details] formatting.

The list can be further prettified, if needed.

UPDATE 1: I’ve traced the type spec names to complete type names.
UPDATE 2: I’ve added a note about which types have Py_TPFLAGS_DISALLOW_INSTANTIATION set, and which types need it set. Ref. msg391905 .
UPDATE 3: Please edit this post if anything is missing!

Commands used to compile this list
# Find commits:
$ git log --oneline -G"^static\s+PyType_Spec" --format=%h > commit.list
# Manually filter out some uninteresting commits (test modules, xx modules, ...)
# Generate markdown list (quick and dirty, could have been more compact):
$ for REF in $(cat commit.list); do \
     git log -n 1 --format="- [%h](https://github.com/python/cpython/commit/%H) %cs " $REF | tr -d "\n" && \
     git diff-tree --no-commit-id --name-only -r $REF | grep "\.c" | grep -v clinic && \
     git log -n 1 -p $REF | gsed -n "s/^+static[ ]\+PyType_Spec[ ]\+\([a-zA-Z_0-9]\+\).*/    - [ ] \`\1\`/p" && \
     echo ""; \
  done > list.md
# Manually filter some of the file references (particularly sqlite3 stuff)
# C&P to Discourse
Raw list of commit refs
0b858cdd5d
c8a87addb1
75bf107c62
dd39123970
6104013838
a6109ef68d
5c36da78d7
01c6aa43dc
74b4eda98b
c8c4200b65
256e54acdb
9031bd4fa4
cb6db8b6ae
a937ab45d6
83de110dce
52a2df135c
2aabc3200b
63f102fe07
31967fd8d0
e087f7cd43
1937edd376
ec68918795
c4862e333a
bf69a8f99f
d5b3f6b7f9
53e4c91725
33f15a16d4
b3966639d2
df69e75edc
f919054e53
04f0bbfbed
ac46eb4ad6
a1ffad0719
4f384af067
11dc6c311d
3b36fb1f53
bc07cb883e
Types converted in Python 3.10
  • 0b858cdd5d 2021-01-04 Modules/cjkcodecs/multibytecodec.c

    • _multibytecodec.MultibyteCodec has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _multibytecodec.MultibyteIncrementalEncoder
    • _multibytecodec.MultibyteIncrementalDecoder
    • _multibytecodec.MultibyteStreamReader
    • _multibytecodec.MultibyteStreamWriter
  • c8a87addb1 2021-01-04 Modules/pyexpat.c

    • pyexpat.xmlparser has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • 75bf107c62 2021-01-02 Modules/arraymodule.c

    • array.array
    • array.arrayiterator has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • dd39123970 2020-12-29 Modules/_functoolsmodule.c

    • functools.partial
    • functools.KeyWrapper has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • functools._lru_list_elem has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • functools._lru_cache_wrapper
  • 6104013838 2020-12-18 Modules/_threadmodule.c

    • _thread.lock has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _thread.RLock
    • _thread._localdummy has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _thread._local
  • a6109ef68d 2020-11-20 Modules/_sre.c

    • re.Pattern has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • re.Match has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _sre.SRE_Scanner has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • 5c36da78d7 2020-11-20 Modules/_ssl.c

    • _ssl._SSLSocket need Py_TPFLAGS_DISALLOW_INSTANTIATION?
    • _ssl._SSLContext
    • _ssl.MemoryBIO
    • _ssl.SSLSession
  • 01c6aa43dc 2020-11-07 Modules/_queuemodule.c

    • _queue.SimpleQueue
  • 74b4eda98b 2020-11-03 Modules/mmapmodule.c

    • mmap.mmap
  • c8c4200b65 2020-10-26 Modules/unicodedata.c

    • unicodedata.UCD has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • 256e54acdb 2020-10-01 Modules/_sqlite

    • sqlite3.Connection
    • sqlite3.Cursor
  • 9031bd4fa4 2020-10-01 Modules/_sqlite

    • sqlite3.Row
    • sqlite3.Statement
  • cb6db8b6ae 2020-09-29 Modules/_sqlite

    • sqlite3.PrepareProtocol
  • a937ab45d6 2020-09-27 Modules/_sqlite

    • sqlite3.Node
    • sqlite3.Cache
  • 83de110dce 2020-09-23 Modules/_lsprof.c

    • _lsprof.Profiler
  • 52a2df135c 2020-09-08 Modules/sha256module.c

    • _sha256.sha224 has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _sha256.sha256 has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • 2aabc3200b 2020-09-07 Modules/overlapped.c

    • _overlapped.Overlapped
  • 63f102fe07 2020-09-06 Modules/md5module.c Modules/sha1module.c Modules/sha512module.c

    • _md5.md5 has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _sha1.sha1 has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _sha512.sha384 has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _sha512.sha512 has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • 31967fd8d0 2020-08-27 Modules/_operator.c

    • operator.itemgetter
    • operator.attrgetter
    • operator.methodcaller
  • e087f7cd43 2020-08-13 Modules/_winapi.c

    • winapi__overlapped.Overlapped has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • 1937edd376 2020-06-23 Modules/_lzmamodule.c

    • _lzma.LZMACompressor
    • _lzma.LZMADecompressor
  • ec68918795 2020-06-20 Modules/_bz2module.c

    • _bz2.BZ2Compressor
    • _bz2.BZ2Decompressor
  • c4862e333a 2020-06-17 Modules/_gdbmmodule.c

    • _gdbm.gdbm has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • bf69a8f99f 2020-06-16 Modules/_dbmmodule.c

    • _dbm.dbm has Py_TPFLAGS_DISALLOW_INSTANTIATION
Types converted in Python 3.9
  • d5b3f6b7f9 2020-05-16 Modules/_hashopenssl.c

    • _hashlib.HASHXOF
  • 53e4c91725 2020-03-30 Modules/_abc.c

    • _abc._abc_data
  • 33f15a16d4 2020-03-27 Modules/_json.c

    • _json.Scanner
    • _json.Encoder
  • b3966639d2 2019-11-05 Modules/posixmodule.c

    • posix.DirEntry has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • posix.ScandirIterator has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • df69e75edc 2019-09-25 Modules/_hashopenssl.c

    • _hashlib.HASH has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • f919054e53 2019-09-14 Modules/selectmodule.c

    • select.devpoll
    • select.kevent need Py_TPFLAGS_DISALLOW_INSTANTIATION
    • select.poll need Py_TPFLAGS_DISALLOW_INSTANTIATION
    • select.epoll
    • select.kqueue
  • 04f0bbfbed 2019-09-13 Modules/_randommodule.c

    • _random.Random
  • ac46eb4ad6 2019-09-11 Python/Python-ast.c (Parser/asdl_c.py)

    • ast.AST
  • a1ffad0719 2019-09-10 Modules/zlibmodule.c

    • zlib.Compress has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • zlib.Decompress has Py_TPFLAGS_DISALLOW_INSTANTIATION
  • 4f384af067 2019-09-10 Modules/_struct.c

    • _struct.unpack_iterator need Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _struct.Struct
Types converted pre Python 3.9

Python 3.4

  • 11dc6c311d 2012-10-14 Modules/_tkinter.c
    • _tkinter.Tcl_Obj has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _tkinter.tktimertoken has Py_TPFLAGS_DISALLOW_INSTANTIATION
    • _tkinter.tkapp has Py_TPFLAGS_DISALLOW_INSTANTIATION

Python 3.1 (?)

  • 3b36fb1f53 2012-06-22 Modules/_ssl.c

    • ssl.SSLError
  • bc07cb883e 2012-06-14 Modules/_curses_panel.c

    • _curses_panel.panel has Py_TPFLAGS_DISALLOW_INSTANTIATION
1 Like

FYI, I’ve traced the PyType_Spec variable names to complete type names. Should be more readable now.

Cc. @vstinner