Repository navigation
fix(corekit): let _py_abc cache its ABC lookups on sentinel types (#1960) - #1966
Conversation
) - SentinelMeta.__setattr__ now lets a frozen sentinel type rebind _abc_negative_cache and _abc_negative_cache_version, and only where the type's own __dict__ already holds them, which only _py_abc puts there. Without the C _abc module, isinstance against a sentinel type raised TypeError. Every other write and every delete is still refused. - New test runs the checks in a child interpreter that really falls back to _py_abc, and pins that the names stay refused under the C module. - The SentinelMeta docstring and the sentinel convention page name the exception. Closes #1960
|
GOOD TO GO at |
- The _PY_ABC_CACHE comment, the SentinelMeta docstring and the sentinel convention page name abc, _py_abc and ABCMeta.__new__ as literals rather than roles, since ABCMeta.__new__ is not in the Python inventory.
|
NEEDS CHANGES at |
|
GOOD TO GO at |
|
Coverage: 90.07% (unit tier, Python 3.15,
Per-file detail: the |
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
Without the C
_abcmodule, as on GraalPy,abcfalls back to_py_abc. That rebinds_abc_negative_cacheand_abc_negative_cache_versionon a class duringisinstance.SentinelMeta.__setattr__refused every write, soisinstance(1, NullType)raisedTypeError, which broke JSON dumping and extraction there (#1960).It now lets exactly those two names through, and only where the type already holds them, which only
_py_abcarranges. Every other write, every delete, andregisteron a concrete type is still refused. The docstring and the sentinel-convention page note the exception.tests/corekit/test_sentinel_py_abc_1960_unit.pyruns the checks in a child interpreter that really takes the_py_abcfallback (abc.ABCMeta is _py_abc.ABCMeta). It fails without the fix on 3.14 and 3.8.Closes #1960