Repository navigation
fix(protocols): decide auto-registration's abstractness without the interpreter's abstract flag (#2784) - #2785
Conversation
…nterpreter's abstract flag (#2784) - GraalPy freezes a class's __flags__ at its first read. Protocol.__init_subclass__ read it through inspect.isabstract before ABCMeta set __abstractmethods__, so every abstract Protocol subclass read as concrete afterwards; registration was right. - Add pcapkit.utilities.inspect.isabstract, which derives the answer from the class namespace and the bases' __abstractmethods__ and reads no flag; the hook uses it. - Tests: an __abstractmethods__ oracle, and a frozen-__flags__ stand-in for GraalPy.
|
Coverage: 94.46% (unit tier, Python 3.15,
Per-file detail: the |
|
GOOD TO GO at |
|
GraalPy re-check, as promised: the leg on |
- Added: pcapkit.utilities.inspect and its isabstract, which decides a class's abstractness from its namespace and its bases' __abstractmethods__ rather than the interpreter's abstract flag, and which Protocol's registration uses (#2785); the defect it fixes never shipped and is not described. - Prepared ahead of #2785 merging, so main is not merged in yet. - CHANGELOG.md regenerated; util/changelog_md.py --check passes.
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
On GraalPy 25.4, an abstract
Protocolsubclass reads as concrete once it is made, so the experimental leg failstest_an_abstract_subclass_is_skipped(#2784).The cause, measured on GraalPy 25.4.4: a class's
__flags__freezes the first time it is read, and setting__abstractmethods__afterwards no longer sets the abstract bit.Protocol.__init_subclass__callsinspect.isabstract, which reads__flags__beforeabc.ABCMetahas set__abstractmethods__. That froze the flag on every subclass. Registration itself was right, so the issue's guess that abstract subclasses got registered was wrong.The fix:
pcapkit.utilities.inspect.isabstractdecides from the class namespace and the bases'__abstractmethods__, asABCMetadoes, without reading any flag. It gives the same answer during__init_subclass__and after.__abstractmethods__instead ofinspect.isabstract. New tests use a stand-in metaclass whose__flags__freezes, or raises, when read, so they fail on unfixedmainunder CPython too.Closes #2784