This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Convert static types to heap types: use PyType_FromSpec()
Type: enhancement Stage: patch review
Components: Extension Modules Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: CharlieZhao, corona10, eric.snow, erlendaasland, h-vetinari, kumaraditya, miss-islington, nw0, pablogsal, petr.viktorin, phsilva, pitrou, serhiy.storchaka, shihai1991, skrah, vstinner
Priority: normal Keywords: patch

Created on 2020-03-26 16:04 by corona10, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
bench_isinstance_check.py corona10, 2020-03-29 02:06
bench_subclass_check.py corona10, 2020-03-29 02:06
bench_isinstance_check.py corona10, 2020-03-29 14:40
Pull Requests
URL Status Linked Edit
PR 19177 merged corona10, 2020-03-26 16:14
PR 19202 merged corona10, 2020-03-28 05:31
PR 19341 closed shihai1991, 2020-04-03 17:38
PR 19344 merged shihai1991, 2020-04-03 17:49
PR 19438 merged shihai1991, 2020-04-08 17:00
PR 20960 merged corona10, 2020-06-18 10:05
PR 20974 closed corona10, 2020-06-19 03:11
PR 21953 closed corona10, 2020-08-25 13:44
PR 21954 merged corona10, 2020-08-25 14:01
PR 23108 merged erlendaasland, 2020-11-02 14:05
PR 23124 merged erlendaasland, 2020-11-03 12:47
PR 23136 merged erlendaasland, 2020-11-03 20:57
PR 23428 closed erlendaasland, 2020-11-20 20:09
PR 23443 serhiy.storchaka, 2020-11-23 10:06
PR 23975 merged erlendaasland, 2020-12-28 11:21
PR 24065 closed erlendaasland, 2021-01-02 23:13
PR 24066 merged erlendaasland, 2021-01-02 23:23
PR 24481 closed erlendaasland, 2021-02-08 08:44
PR 30884 closed CharlieZhao, 2022-01-25 12:29
Messages (47)
msg365087 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-03-26 16:04
Some of modules is not using PyType_FromSpec.
We need to convert them.

This changes can bring
- allow to destroy types at exit!
- allow subinterpreters to have their own "isolated" typ
msg365088 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-26 16:08
> We need to convert them.

Let me elaborate. Static types have multiple issues:

* Their lifetime is not well defined.
* It is not obvious when they are ready to be used.
* They are not destroyed at exit.
* They are incompatible with subinterpreters: each interpreter should have its own copy of a type, rather than static types are shared by all interpreters which cause problems with reference counting (require GIL or atomic operation).
* They are causing issues with stable ABI (limited C API): PEP 384.
msg365117 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-03-26 22:55
Wouldn't having less static types slow down startup time?
msg365125 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-27 01:15
Pablo:
> Wouldn't having less static types slow down startup time?

That's possible, even if I only expect a minor or non significant overhead.

But before starting talking about performances, we should focus on the correctness. Static types are causing issues with subinterpreters and the Python finalization.
msg365142 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-27 11:00
New changeset 33f15a16d40cb8010a8c758952cbf88d7912ee2d by Dong-hee Na in branch 'master':
bpo-40077: Convert _json module to use PyType_FromSpec() (GH-19177)
https://github.com/python/cpython/commit/33f15a16d40cb8010a8c758952cbf88d7912ee2d
msg365145 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2020-03-27 11:46
> Wouldn't having less static types slow down startup time?

Yes, and not only startup time:

https://bugs.python.org/issue15722
msg365149 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-27 13:58
In the _json module, PyModule_GetState() (called by get_json_state()) is only used by the garbage collector (traverse function) and to unload the module (clear and free functions). It's not used in "hot code" (let me consider that the GC is not part of the usual "hot code" :-)).

But maybe we should measure the overhead of future changes if PyModule_GetState() starts to be used in "hot code" by running a few microbenchmarks.

--

Stefan Krah:
> Yes, and not only startup time:
> https://bugs.python.org/issue15722

Aha, that's interesting. I didn't know that it could have an impact on runtime performance as well.

_decimal_pep3121-384_v1.patch attached to bpo-15722 seems to use:

#define _decimal_state_global ((_decimal_state *)PyModule_GetState(PyState_FindModule(&_decimal_module)))

whereas the commit 33f15a16d40cb8010a8c758952cbf88d7912ee2d only uses:

static inline _jsonmodulestate*
get_json_state(PyObject *module)
{
    void *state = PyModule_GetState(module);
    assert(state != NULL);
    return (_jsonmodulestate *)state;
}

Maybe PyState_FindModule() adds a little overhead, even if this function is simple: in short, it gets the i-th item of a list (from PyInterpreterState.modules_by_index).

PyModule_GetState() function is really simple: it only reads PyModuleObject.md_state attribute.

Or maybe _decimal_state_global was used in "hot code".

If PyState_FindModule() or PyModule_GetState() is the source of the overhead, maybe we could try to optimise these functions, or pass directly the module state to inner functions.

--

PyState_FindModule() doesn't work for a module using PyModuleDef_Init(). The PEP 573 is going to give access to the module state in functions which didn't access to it previsouly.

The commit 33f15a16d40cb8010a8c758952cbf88d7912ee2d removed a few assertions checking that "self" has the expected type. It wasn't possible to get the module state to get the types, because PEP 573 is not implemented yet and PyState_FindModule() doesn't work in _json (which uses PyModuleDef_Init()). I decided that it's ok to remove these assertions: it should not be possible to call these functions with another type in practice.

--

In his PR 19177, Dong-hee started by replacing direct access to PyTypeObject fields, like replacing:

    type->free(self);

with:

    freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
    free_func(self);

I asked him to revert these changes.

I'm interested to experiment a few C extension modules of the stdlib using the limited C API (PEP 384, stable ABI), but I don't think that it should done while converting modules to PyType_FromSpec().

We should separate the two changes. And I would prefer to first see the overhead of PyType_FromSpec(), and discuss the advantages and drawbacks.
msg365154 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2020-03-27 14:48
> Or maybe _decimal_state_global was used in "hot code".

Yes, _decimal has problems here that most modules don't have.
Modules like atexit are obviously fine. :)

I just posted it as an example why one should be a bit cautious.


> The PEP 573 is going to give access to the module state in functions which didn't access to it previously.

That could help, we'll see.
msg365205 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-03-28 05:54
> And I would prefer to first see the overhead of PyType_FromSpec(), and discuss the advantages and drawbacks.

Should we stop the work until the overhead is measured?
msg365220 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-28 17:13
> Should we stop the work until the overhead is measured?

Can you try to measure the _abc._abc_instancecheck() and _abc._abc_subclasscheck() functions performance before/after your change? Functions like register() are rarely call, so I don't care much of their performance (I expect a small overhead or no overhead).
msg365241 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-03-29 02:05
It shown 1% slower for performance.

+--------------------------+-----------------+----------------------------+
| Benchmark                | master-subclass | bpo-40077-subclass         |
+==========================+=================+============================+
| bench _abc_subclasscheck | 295 ns          | 300 ns: 1.01x slower (+1%) |
+--------------------------+-----------------+----------------------------+

+--------------------------+-------------------+----------------------------+
| Benchmark                | master-isinstance | bpo-40077-isinstance       |
+==========================+===================+============================+
| bench _abc_instancecheck | 229 ns            | 232 ns: 1.01x slower (+1%) |
+--------------------------+-------------------+----------------------------+
msg365242 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-03-29 02:07
> Can you try to measure the _abc._abc_instancecheck() and _abc._abc_subclasscheck()

I 've submitted the benchmark :)
msg365255 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-29 14:17
IMO 1.01x slower on a *microbenchmark* is not significant so it's ok. Thanks for checking.

You pass a *type to isinstance() in bench_isinstance_check.py. You should pass *an instance* instead. Like (complete the (...) ;-)):

runner.timeit(name="bench _abc_instancecheck",
              stmt="isinstance(obj, T)",
              setup = """from abc import ABC (...) obj = (1, 2, 3)""")

Would you mind to fix your microbenchmark and re-run it?
msg365257 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-03-29 14:40
> You pass a *type to isinstance() in bench_isinstance_check.py.

Thanks for the catch my mistake.

The result is showing:
Not significant (1): bench _abc_instancecheck
msg365317 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-30 14:35
New changeset 53e4c91725083975598350877e2ed8e2d0194114 by Dong-hee Na in branch 'master':
bpo-40077: Convert _abc module to use PyType_FromSpec() (GH-19202)
https://github.com/python/cpython/commit/53e4c91725083975598350877e2ed8e2d0194114
msg365558 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-02 01:56
> bpo-40077: Convert _abc module to use PyType_FromSpec() (GH-19202)

This change introduced a reference leak: bpo-40149 "test_threading leaked [38, 38, 38] references, sum=114".
msg365773 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-04 19:24
New changeset b709302f3125622986bd458dfb2954fda5e8366d by Hai Shi in branch 'master':
bpo-40077: Fix potential refleaks of _json: traverse memo (GH-19344)
https://github.com/python/cpython/commit/b709302f3125622986bd458dfb2954fda5e8366d
msg366024 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2020-04-08 22:39
> Wouldn't having less static types slow down startup time?

FWIW, I've been considering an approach where the main interpreter
keeps using static types but subinterpreters use heap types.  If it
isn't too much effort (or too hacky) then it might be a sufficient
solution for now.
msg366061 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-04-09 15:10
New changeset dcb04d9c6dd6f31449ade6765fa4d26a305e7381 by Hai Shi in branch 'master':
bpo-40077: Remove redundant cast in json module (GH-19438)
https://github.com/python/cpython/commit/dcb04d9c6dd6f31449ade6765fa4d26a305e7381
msg368669 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-11 22:23
See also bpo-40601: [C API] Hide static types from the limited C API.
msg371120 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-09 16:11
I tried to finalize static types in Py_Finalize(), but it didn't work:

* https://bugs.python.org/issue1635741#msg371119
* https://github.com/python/cpython/pull/20763
msg371813 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-18 14:06
PR 20960 (_bz2 module) triggers an interesting question. The effect of converting a static type to a heap type on pickle, especially for protocols 0 and 1.

pickle.dumps(o, 0) calls object.__reduce__(o) which calls copyreg._reduce_ex(o, 0).

copyreg._reduce_ex() behaves differently on heap types:

    ...
    for base in cls.__mro__:
        if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
            break
    else:
        base = object # not really reachable
    ...

There are 3 things which impacts serialization/deserialization:

- Py_TPFLAGS_HEAPTYPE flag in the type flags
- Is __new__() overriden in the type?
- Py_TPFLAGS_BASETYPE flag in the type flags

Examples:

* In Python 3.7, _random.Random() cannot be serialized because it's a static type (it doesn't have (Py_TPFLAGS_HEAPTYPE)
* In master, _random.Random() cannot be deserialized because _random.Random() has __new__() method (it's not object.__new__())
msg371890 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-06-19 15:56
New changeset ec689187957cc80af56b9a63251bbc295bafd781 by Dong-hee Na in branch 'master':
bpo-40077: Convert _bz2 module to use PyType_FromSpec (GH-20960)
https://github.com/python/cpython/commit/ec689187957cc80af56b9a63251bbc295bafd781
msg372073 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-22 09:33
Search also for issues with "384" in their title (34 open issues):

https://bugs.python.org/issue?%40search_text=&ignore=file%3Acontent&title=384&%40columns=title&id=&%40columns=id&stage=&creation=&creator=&activity=&%40columns=activity&%40sort=activity&actor=&nosy=&type=&components=&versions=&dependencies=&assignee=&keywords=&priority=&status=1&%40columns=status&resolution=&nosy_count=&message_count=&%40group=&%40pagesize=50&%40startwith=0&%40sortdir=on&%40queryname=&%40old-queryname=&%40action=search

Search for issues with pep3121 keyword (40 open issues):

https://bugs.python.org/issue?%40search_text=&ignore=file%3Acontent&title=&%40columns=title&id=&%40columns=id&stage=&creation=&creator=&activity=&%40columns=activity&%40sort=activity&actor=&nosy=&type=&components=&versions=&dependencies=&assignee=&keywords=13&priority=&status=1&%40columns=status&resolution=&nosy_count=&message_count=&%40group=&%40pagesize=50&%40startwith=0&%40sortdir=on&%40queryname=&%40old-queryname=&%40action=search
msg372074 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-22 09:33
For example, see bpo-15849 for the xx module.
msg372076 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-22 09:35
See meta bpo-15787 "PEP 3121, 384 Refactoring" which tracks all these issues as dependencies.
msg372326 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-25 09:38
The Tools/scripts/abitype.py script can help to port C extensions to PyType_FromSpec().
msg375943 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-08-26 17:22
New changeset 31967fd8d0220af84e2698172d1378bffc8cd851 by Dong-hee Na in branch 'master':
bpo-40077: Convert _operator to use PyType_FromSpec (GH-21954)
https://github.com/python/cpython/commit/31967fd8d0220af84e2698172d1378bffc8cd851
msg380109 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-01 00:15
Count static types:

grep -E 'static PyTypeObject .* =' $(find -name "*.c"|grep -v Doc/)|wc -l

Count heap types:

grep -E 'PyType_Spec .* =' $(find -name "*.c")|wc -l

Status:

* 3.6: 10 heap (6%) vs 145 static (total: 155)
* 3.7: 10 heap (6%) vs 150 static (total: 160)
* 3.8: 15 heap (9%) vs 157 static (total: 172)
* 3.9: 39 heap (21%) vs 149 static (total: 188) -- 2.6x more heap types than 3.8!
* master: 69 heap (35%) vs 131 static (total: 200) -- 1.8x more heap types than 3.9!

The percentage of heap static is growing in the right direction ;-) The total number of types is also growing at each Python realease!
msg380267 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-03 09:39
New changeset 74b4eda98b650245216292ace8d7e30d3997baa7 by Erlend Egeberg Aasland in branch 'master':
bpo-40077: Convert mmap.mmap static type to a heap type (GH-23108)
https://github.com/python/cpython/commit/74b4eda98b650245216292ace8d7e30d3997baa7
msg380516 - (view) Author: miss-islington (miss-islington) Date: 2020-11-07 19:18
New changeset 01c6aa43dc56b3b64d584c58a49c86f816c05a91 by Erlend Egeberg Aasland in branch 'master':
bpo-40077: Convert _queuemodule to use heap types (GH-23136)
https://github.com/python/cpython/commit/01c6aa43dc56b3b64d584c58a49c86f816c05a91
msg380517 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2020-11-07 19:20
Thank you @erlendaasland !
msg380518 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2020-11-07 19:20
Oops, sorry, I hadn't noticed this was a catch-all issue. Reopening.
msg383848 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-12-27 11:45
Progress: 43% (89/206) of types are declared as heap types on a total of 206 types.

$ grep -E 'static PyTypeObject .* =' $(find -name "*.c"|grep -v Doc/)|wc -l
117
$ grep -E 'PyType_Spec .* =' $(find -name "*.c")|wc -l
89
msg383908 - (view) Author: miss-islington (miss-islington) Date: 2020-12-28 17:47
New changeset bf108bb21e1d75e30bd17141cc531dd08a5e5d0c by Erlend Egeberg Aasland in branch 'master':
bpo-40077: Fix typo in simplequeue_get_state_by_type() (GH-23975)
https://github.com/python/cpython/commit/bf108bb21e1d75e30bd17141cc531dd08a5e5d0c
msg384228 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-01-02 16:38
New changeset 75bf107c62fbdc00af51ee4f6ab69df4bd201104 by Erlend Egeberg Aasland in branch 'master':
bpo-40077: Convert arraymodule to use heap types and establish module state (GH-23124)
https://github.com/python/cpython/commit/75bf107c62fbdc00af51ee4f6ab69df4bd201104
msg384236 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-01-02 19:11
Should Modules/_testcapimodule.c stay untouched?
msg384271 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-01-03 13:11
New changeset b8eb3765908c0063f0739595ba4b296cc8863d19 by Erlend Egeberg Aasland in branch 'master':
bpo-40077: Add traverse/clear/free to arraymodule (GH-24066)
https://github.com/python/cpython/commit/b8eb3765908c0063f0739595ba4b296cc8863d19
msg384272 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-01-03 13:18
Yes, please keep _testcapimodule.c as it is. Static types are still supported and need to be tested.
msg384293 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-01-03 19:00
Ok, perhaps we should leave a comment about that? It already has a comment about multi-phase init.

What about Modules/_testbuffer.c and the xx-modules?

$ grep -E 'static PyTypeObject .* =' $(find . -name "*.c"|grep -vE '(Doc/|Modules/_testcapimodule)') | wc -l
94

$ grep -E 'PyType_Spec .* =' $(find . -name "*.c")|wc -l                                                                                                                            (master)cpython.git
95

We're almost halfway there.
msg410810 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-01-17 17:24
See also bpo-46417 "[subinterpreters] Clear static types in Py_Finalize()".
msg411630 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-01-25 16:50
Converting further static types to heap types require a discussion. See what the Python Steering Council wrote at Feb 8, 2021:

"The Steering Council discussed the ongoing work on porting types in the standard library to heap-types and the subinterpreter-related changes. It was decided that through Pablo, the Steering Council will ask the core developers driving those changes to create an informational PEP and not to make any more changes in this area after beta 1, as per our general policy."

https://github.com/python/steering-council/blob/1d85eefdc5861a096c3859e9990dbc8527c5973b/updates/2021-02-steering-council-update.md
msg411903 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-01-27 17:33
I used the following shell command to search remaining static types:
---
grep -E 'static PyTypeObject [a-zA-Z_0-9]+ *(;|= *{|) *$' $(find -name "*.c")
---

I found 86 static types in 17 files:

* PC/_msi.c:

  * msidb_Type
  * msiview_Type
  * record_Type
  * summary_Type

* Modules/_ctypes/_ctypes.c:

  * DictRemover_Type
  * PyComError_Type
  * PyDec_Type
  * Simple_Type
  * StructParam_Type
  * Struct_Type
  * UnionType_Type
  * Union_Type

* Modules/_decimal/_decimal.c:

  * PyDecContextManager_Type
  * PyDecContext_Type
  * PyDecSignalDict_Type

* Modules/xxmodule.c:

  * Null_Type
  * Str_Type
  * Xxo_Type

* Modules/_testbuffer.c:

  * NDArray_Type
  * StaticArray_Type

* Modules/itertoolsmodule.c (multiphase init):

  * _grouper_type
  * accumulate_type
  * combinations_type
  * compress_type
  * count_type
  * cwr_type
  * cycle_type
  * dropwhile_type
  * filterfalse_type
  * groupby_type
  * pairwise_type
  * permutations_type
  * starmap_type
  * takewhile_type
  * tee_type
  * teedataobject_type

* Modules/_xxsubinterpretersmodule.c:

  * ChannelIDtype

* Modules/_datetimemodule.c:

  * PyDateTime_DateTimeType
  * PyDateTime_DateType
  * PyDateTime_DeltaType
  * PyDateTime_IsoCalendarDateType
  * PyDateTime_TZInfoType
  * PyDateTime_TimeType
  * PyDateTime_TimeZoneType

* Modules/_testcapimodule.c:

  * ContainerNoGC_type
  * GenericAlias_Type
  * Generic_Type
  * MethClass_Type
  * MethInstance_Type
  * MethStatic_Type
  * MethodDescriptor2_Type
  * MethodDescriptorBase_Type
  * MethodDescriptorDerived_Type
  * MethodDescriptorNopGet_Type
  * MyList_Type
  * PyRecursingInfinitelyError_Type
  * _HashInheritanceTester_Type
  * awaitType
  * ipowType
  * matmulType
  * test_structmembersType

* Modules/_zoneinfo.c:

  * PyZoneInfo_ZoneInfoType

* Modules/ossaudiodev.c:

  * OSSAudioType
  * OSSMixerType

* Modules/socketmodule.c:

  * sock_type

* Modules/xxsubtype.c:

  * spamdict_type
  * spamlist_type

* Modules/_collectionsmodule.c:

  * defdict_type
  * deque_type
  * dequeiter_type
  * dequereviter_type
  * tuplegetter_type

* Modules/_elementtree.c:

  * ElementIter_Type
  * Element_Type
  * TreeBuilder_Type
  * XMLParser_Type

* Modules/_pickle.c:

  * Pdata_Type
  * PicklerMemoProxyType
  * Pickler_Type
  * UnpicklerMemoProxyType
  * Unpickler_Type

* Modules/_asynciomodule.c:

  * FutureIterType
  * FutureType
  * PyRunningLoopHolder_Type
  * TaskStepMethWrapper_Type
  * TaskType
msg411904 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-01-27 17:39
And I found 135 more static types with this command:
---
grep -E '^PyTypeObject [a-zA-Z_0-9]+ *(;|= *{|) *$' $(find -name "*.c")
---

Types:

Objects/cellobject.c: PyCell_Type
Objects/sliceobject.c: PyEllipsis_Type
Objects/sliceobject.c: PySlice_Type
Objects/unionobject.c: _PyUnion_Type
Objects/methodobject.c: PyCFunction_Type
Objects/methodobject.c: PyCMethod_Type
Objects/picklebufobject.c: PyPickleBuffer_Type
Objects/boolobject.c: PyBool_Type
Objects/bytearrayobject.c: PyByteArray_Type
Objects/bytearrayobject.c: PyByteArrayIter_Type
Objects/classobject.c: PyMethod_Type
Objects/classobject.c: PyInstanceMethod_Type
Objects/fileobject.c: PyStdPrinter_Type
Objects/genericaliasobject.c: Py_GenericAliasType
Objects/interpreteridobject.c: _PyInterpreterID_Type
Objects/iterobject.c: PySeqIter_Type
Objects/iterobject.c: PyCallIter_Type
Objects/iterobject.c: _PyAnextAwaitable_Type
Objects/moduleobject.c: PyModuleDef_Type
Objects/moduleobject.c: PyModule_Type
Objects/rangeobject.c: PyRange_Type
Objects/rangeobject.c: PyRangeIter_Type
Objects/rangeobject.c: PyLongRangeIter_Type
Objects/namespaceobject.c: _PyNamespace_Type
Objects/bytesobject.c: PyBytes_Type
Objects/bytesobject.c: PyBytesIter_Type
Objects/capsule.c: PyCapsule_Type
Objects/complexobject.c: PyComplex_Type
Objects/dictobject.c: PyDict_Type
Objects/dictobject.c: PyDictIterKey_Type
Objects/dictobject.c: PyDictIterValue_Type
Objects/dictobject.c: PyDictIterItem_Type
Objects/dictobject.c: PyDictRevIterKey_Type
Objects/dictobject.c: PyDictRevIterItem_Type
Objects/dictobject.c: PyDictRevIterValue_Type
Objects/dictobject.c: PyDictKeys_Type
Objects/dictobject.c: PyDictItems_Type
Objects/dictobject.c: PyDictValues_Type
Objects/floatobject.c: PyFloat_Type
Objects/frameobject.c: PyFrame_Type
Objects/funcobject.c: PyFunction_Type
Objects/funcobject.c: PyClassMethod_Type
Objects/funcobject.c: PyStaticMethod_Type
Objects/memoryobject.c: _PyManagedBuffer_Type
Objects/memoryobject.c: PyMemoryView_Type
Objects/odictobject.c: PyODict_Type
Objects/odictobject.c: PyODictIter_Type
Objects/odictobject.c: PyODictKeys_Type
Objects/odictobject.c: PyODictItems_Type
Objects/odictobject.c: PyODictValues_Type
Objects/setobject.c: PySetIter_Type
Objects/setobject.c: PySet_Type
Objects/setobject.c: PyFrozenSet_Type
Objects/setobject.c: _PySetDummy_Type
Objects/tupleobject.c: PyTuple_Type
Objects/tupleobject.c: PyTupleIter_Type
Objects/object.c: _PyNone_Type
Objects/object.c: _PyNotImplemented_Type
Objects/unicodeobject.c: PyUnicode_Type
Objects/unicodeobject.c: PyUnicodeIter_Type
Objects/listobject.c: PyList_Type
Objects/listobject.c: PyListIter_Type
Objects/listobject.c: PyListRevIter_Type
Objects/genobject.c: PyGen_Type
Objects/genobject.c: PyCoro_Type
Objects/genobject.c: _PyCoroWrapper_Type
Objects/genobject.c: PyAsyncGen_Type
Objects/genobject.c: _PyAsyncGenASend_Type
Objects/genobject.c: _PyAsyncGenWrappedValue_Type
Objects/genobject.c: _PyAsyncGenAThrow_Type
Objects/longobject.c: PyLong_Type
Objects/descrobject.c: PyMethodDescr_Type
Objects/descrobject.c: PyClassMethodDescr_Type
Objects/descrobject.c: PyMemberDescr_Type
Objects/descrobject.c: PyGetSetDescr_Type
Objects/descrobject.c: PyWrapperDescr_Type
Objects/descrobject.c: _PyMethodWrapper_Type
Objects/descrobject.c: PyDictProxy_Type
Objects/descrobject.c: PyProperty_Type
Objects/enumobject.c: PyEnum_Type
Objects/enumobject.c: PyReversed_Type
Objects/codeobject.c: _LineIterator
Objects/codeobject.c: _PositionsIterator
Objects/codeobject.c: PyCode_Type
Objects/typeobject.c: PyType_Type
Objects/typeobject.c: PyBaseObject_Type
Objects/typeobject.c: PySuper_Type
Python/bltinmodule.c: PyFilter_Type
Python/bltinmodule.c: PyMap_Type
Python/bltinmodule.c: PyZip_Type
Python/context.c: PyContext_Type
Python/context.c: PyContextVar_Type
Python/context.c: PyContextToken_Type
Python/context.c: _PyContextTokenMissing_Type
Python/hamt.c: _PyHamtItems_Type
Python/hamt.c: _PyHamtKeys_Type
Python/hamt.c: _PyHamtValues_Type
Python/hamt.c: _PyHamt_Type
Python/hamt.c: _PyHamt_ArrayNode_Type
Python/hamt.c: _PyHamt_BitmapNode_Type
Python/hamt.c: _PyHamt_CollisionNode_Type
Python/traceback.c: PyTraceBack_Type
Python/symtable.c: PySTEntry_Type
Modules/_ctypes/callproc.c: PyCArg_Type
Modules/_ctypes/_ctypes.c: PyCStructType_Type
Modules/_ctypes/_ctypes.c: PyCPointerType_Type
Modules/_ctypes/_ctypes.c: PyCArrayType_Type
Modules/_ctypes/_ctypes.c: PyCSimpleType_Type
Modules/_ctypes/_ctypes.c: PyCFuncPtrType_Type
Modules/_ctypes/_ctypes.c: PyCData_Type
Modules/_ctypes/_ctypes.c: PyCFuncPtr_Type
Modules/_ctypes/_ctypes.c: PyCArray_Type
Modules/_ctypes/_ctypes.c: PyCPointer_Type
Modules/_ctypes/cfield.c: PyCField_Type
Modules/_ctypes/stgdict.c: PyCStgDict_Type
Modules/_ctypes/callbacks.c: PyCThunk_Type
Modules/_io/iobase.c: PyIOBase_Type
Modules/_io/iobase.c: PyRawIOBase_Type
Modules/_io/stringio.c: PyStringIO_Type
Modules/_io/textio.c: PyTextIOBase_Type
Modules/_io/textio.c: PyIncrementalNewlineDecoder_Type
Modules/_io/textio.c: PyTextIOWrapper_Type
Modules/_io/bytesio.c: PyBytesIO_Type
Modules/_io/fileio.c: PyFileIO_Type;
Modules/_io/fileio.c: PyFileIO_Type
Modules/_io/winconsoleio.c: PyWindowsConsoleIO_Type;
Modules/_io/winconsoleio.c: PyWindowsConsoleIO_Type
Modules/_io/bufferedio.c: PyBufferedIOBase_Type
Modules/_io/bufferedio.c: PyBufferedReader_Type
Modules/_io/bufferedio.c: PyBufferedWriter_Type
Modules/_io/bufferedio.c: PyBufferedRWPair_Type
Modules/_io/bufferedio.c: PyBufferedRandom_Type
Modules/_multiprocessing/semaphore.c: _PyMp_SemLockType
Modules/_cursesmodule.c: PyCursesWindow_Type;
Modules/_cursesmodule.c: PyCursesWindow_Type
msg411907 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-01-27 17:48
> And I found 135 more static types with this command

Of these 135 static types, most are cleared since bpo-46417 was implemented:

* 103 types are cleared by _PyTypes_FiniTypes()
* 15 types are cleared by _PyIO_Fini()
* the remaining 17 types are not cleared at Python exit: types of _ctypes, _curses and _multiprocessing extensions
msg411964 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-01-28 02:42
I marked bpo-23769 "valgrind reports leaks for test_zipimport" as duplicate of this issue. At exit, Python doesn't clear the static types of the _collections, itertools and _struct extensions:

* itertools.accumulate
* itertools.combinations
* itertools.combinations_with_replacement
* itertools.cycle
* itertools.dropwhile
* itertools.takewhile
* itertools.islice
* itertools.starmap
* itertools.chain
* itertools.compress
* itertools.filterfalse
* itertools.count
* itertools.zip_longest
* itertools.pairwise
* itertools.permutations
* itertools.product
* itertools.repeat
* itertools.groupby
* itertools._grouper
* itertools._tee
* itertools._tee_dataobject
* collections.deque
* _collections._deque_iterator
* _collections._deque_reverse_iterator
* _collections._tuplegetter
* _struct.Struct
* _struct.unpack_iterator

See: https://bugs.python.org/issue23769#msg411963
msg412338 - (view) Author: Kumar Aditya (kumaraditya) * (Python triager) Date: 2022-02-02 05:50
On Windows PC/winreg.c has PyHKEY_Type static type which isn't cleared at exit too.
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84258
2022-02-02 05:50:10kumaradityasetnosy: + kumaraditya
messages: + msg412338
2022-01-28 02:42:11vstinnersetmessages: + msg411964
2022-01-28 02:41:02vstinnerlinkissue23769 superseder
2022-01-27 17:48:51vstinnersetmessages: + msg411907
2022-01-27 17:39:11vstinnersetmessages: + msg411904
2022-01-27 17:33:24vstinnersetmessages: + msg411903
2022-01-25 16:50:51vstinnersetmessages: + msg411630
2022-01-25 12:29:21CharlieZhaosetnosy: + CharlieZhao
pull_requests: + pull_request29065
2022-01-17 17:24:15vstinnersetmessages: + msg410810
2021-06-29 17:31:43h-vetinarisetnosy: + h-vetinari
2021-02-18 14:02:57nw0setnosy: + nw0
2021-02-08 08:44:29erlendaaslandsetpull_requests: + pull_request23273
2021-01-03 19:00:39erlendaaslandsetmessages: + msg384293
2021-01-03 13:18:17petr.viktorinsetmessages: + msg384272
2021-01-03 13:11:33petr.viktorinsetmessages: + msg384271
2021-01-02 23:23:21erlendaaslandsetpull_requests: + pull_request22899
2021-01-02 23:13:48erlendaaslandsetpull_requests: + pull_request22898
2021-01-02 19:11:56erlendaaslandsetmessages: + msg384236
2021-01-02 16:38:59petr.viktorinsetnosy: + petr.viktorin
messages: + msg384228
2020-12-28 17:47:35miss-islingtonsetmessages: + msg383908
2020-12-28 11:21:47erlendaaslandsetpull_requests: + pull_request22819
2020-12-27 11:45:46vstinnersetmessages: + msg383848
2020-11-23 10:06:09serhiy.storchakasetnosy: + serhiy.storchaka
pull_requests: + pull_request22364
2020-11-20 20:09:00erlendaaslandsetstage: patch review
pull_requests: + pull_request22319
2020-11-07 19:20:52pitrousetstatus: closed -> open
resolution: fixed ->
messages: + msg380518

stage: resolved -> (no value)
2020-11-07 19:20:16pitrousetstatus: open -> closed

type: enhancement
components: + Extension Modules, - C API, Subinterpreters

nosy: + pitrou
messages: + msg380517
resolution: fixed
stage: patch review -> resolved
2020-11-07 19:18:44miss-islingtonsetnosy: + miss-islington
messages: + msg380516
2020-11-03 20:57:29erlendaaslandsetpull_requests: + pull_request22050
2020-11-03 12:47:12erlendaaslandsetpull_requests: + pull_request22040
2020-11-03 09:39:06vstinnersetmessages: + msg380267
2020-11-03 04:16:19shihai1991setversions: + Python 3.10, - Python 3.9
2020-11-02 14:05:20erlendaaslandsetpull_requests: + pull_request22025
2020-11-01 00:15:42vstinnersetmessages: + msg380109
2020-09-16 10:06:57vstinnersettitle: Convert static types to PyType_FromSpec() -> Convert static types to heap types: use PyType_FromSpec()
2020-08-26 17:22:37corona10setmessages: + msg375943
2020-08-25 14:01:06corona10setpull_requests: + pull_request21063
2020-08-25 13:44:36corona10setpull_requests: + pull_request21062
2020-06-25 09:38:33vstinnersetmessages: + msg372326
2020-06-22 09:35:00vstinnersetmessages: + msg372076
2020-06-22 09:33:27vstinnersetmessages: + msg372074
2020-06-22 09:33:12vstinnersetmessages: + msg372073
2020-06-19 15:56:17corona10setmessages: + msg371890
2020-06-19 03:11:11corona10setpull_requests: + pull_request20151
2020-06-18 14:06:36vstinnersetmessages: + msg371813
2020-06-18 10:05:34corona10setpull_requests: + pull_request20139
2020-06-09 18:59:43erlendaaslandsetnosy: + erlendaasland
2020-06-09 16:11:56vstinnersetmessages: + msg371120
2020-06-05 09:32:54vstinnersetcomponents: + Subinterpreters
2020-05-11 22:23:59vstinnersetmessages: + msg368669
2020-04-09 15:10:36corona10setmessages: + msg366061
2020-04-08 22:39:48eric.snowsetnosy: + eric.snow
messages: + msg366024
2020-04-08 17:00:41shihai1991setpull_requests: + pull_request18792
2020-04-04 19:24:23vstinnersetmessages: + msg365773
2020-04-03 17:49:13shihai1991setpull_requests: + pull_request18708
2020-04-03 17:38:26shihai1991setpull_requests: + pull_request18705
2020-04-02 01:56:23vstinnersetmessages: + msg365558
2020-03-30 14:52:13shihai1991setnosy: + shihai1991
2020-03-30 14:35:44vstinnersetmessages: + msg365317
2020-03-29 14:40:48corona10setfiles: + bench_isinstance_check.py

messages: + msg365257
2020-03-29 14:17:02vstinnersetmessages: + msg365255
2020-03-29 02:07:21corona10setmessages: + msg365242
2020-03-29 02:06:47corona10setfiles: + bench_subclass_check.py
2020-03-29 02:06:38corona10setfiles: + bench_isinstance_check.py
2020-03-29 02:05:45corona10setmessages: + msg365241
2020-03-28 17:13:18vstinnersetmessages: + msg365220
2020-03-28 05:54:13corona10setmessages: + msg365205
2020-03-28 05:31:04corona10setpull_requests: + pull_request18565
2020-03-27 14:48:11skrahsetmessages: + msg365154
2020-03-27 13:58:10vstinnersetmessages: + msg365149
2020-03-27 11:46:53skrahsetnosy: + skrah
messages: + msg365145
2020-03-27 11:00:12vstinnersetmessages: + msg365142
2020-03-27 03:17:47corona10setcomponents: + C API
2020-03-27 03:17:41corona10setversions: + Python 3.9
2020-03-27 01:19:29phsilvasetnosy: + phsilva
2020-03-27 01:15:29vstinnersetmessages: + msg365125
2020-03-26 22:55:59pablogsalsetmessages: + msg365117
2020-03-26 22:55:53pablogsalsetmessages: - msg365116
2020-03-26 22:55:46pablogsalsetnosy: + pablogsal
messages: + msg365116
2020-03-26 16:14:23corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request18537
2020-03-26 16:08:39vstinnersetmessages: + msg365088
2020-03-26 16:04:44corona10create