gh-119180: Alternative approach to metaclass annotations: never use the dict by JelleZijlstra · Pull Request #120816 · python/cpython
Like #120719, this is an experimental way to fix the issues discussed in python/peps#3847.
This PR takes the approach of "never use the class dict". Instead, we repurpose the unused tp_cache field to hold annotation information. It can hold any of:
- NULL: the class has no annotations
- a dict: the class has
__annotations__, but no__annotate__ - a callable: the class has only
__annotate__ - a tuple: the class has both annotate and annotations