mirror of
https://github.com/python/cpython.git
synced 2025-11-08 09:32:01 +00:00
This partially reverts #137047, keeping the tests for GC collectability of the original class that dataclass adds `__slots__` to. The reference leaks solved there are instead solved by having the `__dict__` & `__weakref__` descriptors not tied to (and referencing) their class. Instead, they're shared between all classes that need them (within an interpreter). The `__objclass__` ol the descriptors is set to `object`, since these descriptors work with *any* object. (The appropriate checks were already made in the get/set code, so the `__objclass__` check was redundant.) The repr of these descriptors (and any others whose `__objclass__` is `object`) now doesn't mention the objclass. This change required adjustment of introspection code that checks `__objclass__` to determine an object's “own” (i.e. not inherited) `__dict__`. Third-party code that does similar introspection of the internals will also need adjusting. Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> |
||
|---|---|---|
| .. | ||
| c_analyzer | ||
| c_common | ||
| c_parser | ||
| cpython | ||
| distutils | ||
| c-analyzer.py | ||
| check-c-globals.py | ||
| must-resolve.sh | ||
| README | ||
| table-file.py | ||
| TODO | ||
####################################### # C Globals and CPython Runtime State. CPython's C code makes extensive use of global variables. Each global falls into one of several categories: * (effectively) constants (incl. static types) * globals used exclusively in main or in the REPL * freelists, caches, and counters * process-global state * module state * Python runtime state Of the different categories, the last two are problematic and generally should not exist in the codebase. Globals that hold module state (i.e. in Modules/*.c) cause problems when multiple interpreters are in use. For more info, see PEP 3121, which addresses the situation for extension modules in general. Globals in the last category should be avoided as well. The problem isn't with the Python runtime having state. Rather, the problem is with that state being spread throughout the codebase in dozens of individual globals. Unlike the other globals, the runtime state represents a set of values that are constantly shifting in a complex way. When they are spread out it's harder to get a clear picture of what the runtime involves. Furthermore, when they are spread out it complicates efforts that change the runtime. Consequently, the globals for Python's runtime state have been consolidated under a single top-level _PyRuntime global. No new globals should be added for runtime state. Instead, they should be added to _PyRuntimeState or one of its sub-structs. The check-c-globals script should be run to ensure that no new globals have been added: python3 Tools/c-analyzer/check-c-globals.py You can also use the more generic tool: python3 Tools/c-analyzer/c-analyzer.py If it reports any globals then they should be resolved. If the globals are runtime state then they should be folded into _PyRuntimeState.