`sys._clear_internal_caches()` no longer clears the type cache
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Documentation
Doc/library/sys.rst says sys._clear_type_cache() clears the internal type cache, and that sys._clear_internal_caches() clears all internal performance-related caches. Neither does any more. Both reach it only through PyType_ClearCache(), which is now just return NEXT_VERSION_TAG(interp) - 1;.
import sys, _testinternalcapi
class C:
x = 'v'
C.x # populate the per-type lookup cache
print("cached: ", _testinternalcapi.type_cache_lookup(C, 'x'))
sys._clear_type_cache()
print("after sys._clear_type_cache: ", _testinternalcapi.type_cache_lookup(C, 'x'))
sys._clear_internal_caches()
print("after sys._clear_internal_caches:", _testinternalcapi.type_cache_lookup(C, 'x'))
cached: (1, 'v', 131161)
after sys._clear_type_cache: (1, 'v', 131161)
after sys._clear_internal_caches: (1, 'v', 131161)
The C API side is already documented. Doc/c-api/type.rst says the function is now a no-op, and GH-150160 added a matching porting note. The Python wrappers look like the spot that was missed.
Linked PRs
- gh-155378
- gh-155391
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Python wrappers for sys._clear_type_cache() and sys._clear_internal_caches(), then compare their behavior with Doc/library/sys.rst and the no-op description in Doc/c-api/type.rst. Check the existing tests around these functions and the porting note from GH-150160; done means the wrappers, documentation, and tests consistently reflect the current behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100