Repository navigation
Fix instantiating a class that fulfills an expectation its base-class missed - #532
Merged
Merged
Conversation
10 of 12 tasks
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| UnusedCode | 1 minor |
🟢 Metrics 14 complexity · 0 duplication
Metric Results Complexity 14 Duplication 0
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #532 +/- ##
======================================
Coverage ? 87.18%
======================================
Files ? 59
Lines ? 14670
Branches ? 2279
======================================
Hits ? 12790
Misses ? 1488
Partials ? 392
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
… missed
A class fulfilling an expectation its base-class missed (a mixin-class'
'expects' naming a member only the derived class defines) couldn't be
instantiated with parameters, and neither could a class derived from it:
TypeError: object.__new__() takes exactly one argument
'_wrapNewMethodIfExpectationUnfulfilled' put 'object.__new__' back into the
class' dictionary, which hits python/cpython#105888: the class keeps
'slot_tp_new', and 'object.__new__' then rejects every parameter.
'_wrapNewMethodIfAbstract' already worked around it with 'wrapped_new'.
Both paths share that workaround now in '_restoreNewMethod'.
Instance creation (ns, median of 4 interleaved rounds, best of 7 x 200k,
core 6), dev -> branch:
- 3.14: Leaf() 189 -> 253, Leaf(1) raised -> 312; a plain class and a
concrete class derived from an abstract one unchanged (+-3 %).
- 3.13: Leaf() 107 -> 174, Leaf(1) raised -> 204; controls unchanged.
A zero-argument constructor of such a class now pays the Python-level
'__new__' like a class that isn't abstract anymore (Concrete(): 264 / 174).
Class creation: unchanged within noise (+-7 %).
Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
pytooling-claude
Bot
force-pushed
the
claude/extendedtype-expects-new
branch
from
October 11, 2026 21:37
e1557cf to
64832f8
Compare
This was referenced Oct 11, 2026
Merged
Merged
Merged
Merged
This was referenced Oct 20, 2026
Merged
Merged
Merged
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Fixes
pyTooling.MetaClasses:A class that fulfilled an expectation its base-class missed (a mixin-class'
expectsnaming a member only the derived class defines) couldn't be instantiated with parameters, and neither could a class derived from it:ExtendedTypereplacedMid.__new__by one raisingUnfulfilledExpectationError, and putobject.__new__back intoLeaf's dictionary. That hits python/cpython#105888:Leafkeeps the inheritedslot_tp_new, soobject.__new__rejects every parameter. A constructor without parameters worked.The path for a class that isn't abstract anymore already worked around it with
wrapped_new, which callsobject.__new__with the class only. Both paths share that workaround now inExtendedType._restoreNewMethod.Mid(1)still raisesUnfulfilledExpectationErrorwith the same message and notes.Known Issues
Instance creation of such a class without parameters is slower, because
__new__is a Python function now, as for a concrete class derived from an abstract one. Median of 4 interleaved rounds (best of 7 × 200 000), dev → this PR:Leaf()Leaf(1)Concrete()(derived from an abstract class, for comparison)Root(),Root(1)(control)Class creation is unchanged within noise (±7 %). Avoiding the Python-level
__new__needs the same decision as for concrete subclasses of abstract classes (ExtendedType: speed analysis and improvements #531).Documentation
doc/News.rst: entry under Bug Fixes.Unit Tests
Instantiationintests/unit/MetaClasses/ExpectedMembers.py: positional and keyword parameters through the fulfilling class, a class derived from it, an abstract class between the incomplete and the fulfilling class, a constructor without parameters, and the incomplete class still rejecting instantiation with the same message. The four tests passing parameters fail ondev.Related Issues and Pull-Requests
ExtendedType; besidesdoc/News.rst, they don't overlap with this change.@expectsmethod (separate PR) adds adoc/News.rstentry at the same place.