Repository navigation
Support super().prop for pyscript properties - #923
Merged
craigbarratt merged 1 commit intoNov 22, 2026
Merged
Conversation
super().prop and super(C, self).prop returned a coroutine instead of the value, since the object is a super and pyscript only looked for a property along type(obj).__mro__, so Python called the pyscript getter itself. For a super object, pyscript now searches the mro of __self_class__ after __thisclass__, as Python does, and awaits a pyscript getter on a plain property with __self__. The super object's members and each class's mro and dict are read through the built-in descriptors, and the getter is checked by its real type, so a parent's attribute with the same name, a metaclass's __getattribute__ or a getter's own hooks can't change the lookup. As in Python, the getter's AttributeError isn't passed to __getattr__, and a class's own __getattribute__ isn't used. Everything else, including super(C, cls) on a class, __class__, property subclasses and compiled getters, is left to Python. Tests compare 28 scripts with CPython, and the docs no longer list super().prop as not working. Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
This was referenced Nov 22, 2026
craigbarratt
approved these changes
Nov 22, 2026
craigbarratt
left a comment
Member
There was a problem hiding this comment.
Thanks @HoneyBearTech, looks good. Approving.
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.
What was broken
Since #918,
obj.propcalls a pyscript property's getter, butsuper().propstill didn't. It returned a coroutine instead of the value, so the most common use, a subclass property that extends its parent's, failed:The same happened with
super(Child, self).label, in a plain method as well as in a getter, and with a metaclass property read throughsuper().Why
Pyscript runs a pyscript getter itself, because Python can't call pyscript's async functions. To find the property it looks along
type(obj).__mro__. Forsuper().labelthe object is asuperobject, andtype(obj)issuper, which has nolabel. So pyscript left the lookup to Python, and Python called the pyscript getter like a normal function, which gives back a coroutine.What I changed
As suggested in the review of #918, the property is now looked up in the MRO after
__thisclass__when the object is asuper:super_property(sup, attr)(new, ineval.py) finds the attribute the way Python'ssuperdoes: it searches__self_class__.__mro__after__thisclass__and stops at the first class that has the attribute. It returns that attribute only when it is a plainproperty, and only when__self__is not__self_class__. Like Python, it reads thesuperobject's__self__,__self_class__and__thisclass__, and each class's__mro__and__dict__, through the built-in descriptors. Asuperobject would otherwise look those names up in the parent classes first, and a metaclass's__getattribute__or data descriptor could intercept a class's.ast_attribute: when the object is exactly asuperobject and that property's getter is a pyscript function, checked by the getter's real type so that nothing on a native getter (such as a hooked__class__) is read, pyscript awaits the getter with thesuperobject's own__self__. As in Python, anAttributeErrorfrom the getter goes straight to the caller, without the__getattr__fallback thatobj.prophas, and a class's own__getattribute__isn't used. This check comes after the existing state-variable, assignment and__init__handling. On other attribute loads it costs one type check.super().__class__, which Python never searches for, so it is stillsupereven if a parent defines a__class__property;super(C);super(C, cls).propon a class, where Python returns the property object itself;AttributeErrormessage as Python);superobject whose__thisclass__is no longer in the MRO, for example after__bases__changes (sameAttributeErroras Python);propertysubclass, a compiled (@pyscript_compile) or native getter, and a subclass ofsuper.super()isn't supported by Python, and it isn't here either:super().prop = valueanddel super().propraise the sameAttributeErroras Python.Testing
One new test in
tests/test_unit_eval.py,test_super_property_match_python, with 28 scripts. Like the #918 tests, it runs each script in CPython and in pyscript and compares the results. It also checks that running each script in pyscript gives no "coroutine was never awaited" warning, except for the__class__script, whereisinstance()inside pyscript itself reads the pyscript__class__getter. The scripts cover:super().propandsuper(C, self).propin a method and in an overriding getter;AttributeError, in a class with__getattr__: no fallback throughsuper(), whileobj.propstill falls back;fractions.Fraction.numerator);super().propandsuper(C, cls).propin a class method, which give the property object;__getattribute__, whichsuper()doesn't use;super(C, self).propin a generator expression and in list comprehensions (also zero-argumentsuper()in a comprehension), and zero-argumentsuper()in a generator expression, which raises the sameTypeErroras Python;super()andsuper(Meta, cls);__class__property on a parent, wheresuper().__class__is stillsuper;superwith its own__getattribute__;propertysubclass, and an unboundsuper(C);super()after the class's__bases__change, and asuperobject whose__thisclass__is no longer in the MRO;super(), and calling a parent's setter withsuper(C, type(self)).prop.fset(self, value)from an overriding setter;__self_class__attribute, or compiled properties named__self__or__thisclass__, whichsuper()ignores, and a parent's__self__attribute, which doesn't change the instance the getter gets;__getattribute__, or a data descriptor on it, blocks__mro__or__dict__, whichsuper()doesn't use;__getattribute__blocks__class__, whichsuper()doesn't read.Without this change, 10 of the 28 scripts fail. The other 18 check behaviour that already worked and must stay the same.
The full test suite, ruff, pylint, mypy, codespell and
sphinx-build -Wpass on Python 3.14. The extra check on ordinary attribute loads is one type check, about 17 ns, which is well under 1% of an attribute load in pyscript. On a microbenchmark that does little but attribute loads, the best of 50 runs was 1.51 s on master and 1.54 s with this change, which is inside the spread between rounds of the same code (up to 8%).Docs
The
@propertyitem in Language Limitations no longer listssuper().propas not working. It now says:super().propandsuper(Cls, self).propcall a parent class's getter, so a subclass's property can extend its parent's;super().prop = valueanddel super().propraiseAttributeError, andsuper(Cls, type(self)).prop.fset(self, value)calls a parent class's setter;propertysubclass still doesn't work, also throughsuper();super()isn't affected by a class's own__getattribute__, sincesuper()doesn't use it, as in Python.Note
This is one commit on master after #918. My open #919 (lambdas) and #920 (
StopIteration) also changeeval.pyand add tests at the end oftests/test_unit_eval.py. Whichever merges later needs a small rebase, and I'm happy to do it.One existing difference isn't fixed here: reading a property through an instance (
obj.prop, notsuper()) whose getter is a native callable with a__getattribute__that blocks__class__raises the error from that__getattribute__in pyscript, on master too, while Python returns the value. That's because #918's property check usesisinstance()on the getter. It's a separate change, so I left it out of this PR.