Repository navigation
Support @property and @classmethod on pyscript class methods - #918
Open
HoneyBearTech wants to merge 1 commit into
Open
HoneyBearTech wants to merge 1 commit into
HoneyBearTech wants to merge 1 commit into
Conversation
A property or classmethod wrapping a pyscript method failed with "'EvalFunc' object is not callable", since the wrapped function is async and Python can't call it. Attribute reads now call a pyscript property getter, assignments (including +=) call the setter, and a classmethod bound to a class is called as a pyscript function. Python's own rules for which attribute wins are kept: a class that overrides __getattribute__ or __setattr__ still gets them called, and an AttributeError from a getter falls back to __getattr__. Docs list what still doesn't work. Signed-off-by: Sean Stoube <[email protected]>
This was referenced Nov 21, 2026
Member
|
Thanks @HoneyBearTech, this works well, and the CPython comparisons are thorough. Things to update:
|
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
@propertyand@classmethodon pyscript methods failed withTypeError: 'EvalFunc' object is not callable. Python calls the getter, setter or class method itself, and it can't call pyscript's async functions:What I changed
ast_attribute: when the class's MRO resolves the name to apropertywhose getter is a pyscript function, the getter is awaited. A getter that raisesAttributeErrorfalls back to the class's__getattr__, bound as Python binds it.EvalAttrSet.setattr_asyncawaits a pyscript setter. All assignment forms go through it, including+=, tuple targets andfor obj.x in .... A read-only property still raises Python's ownAttributeError.call_funcawaits a bound method whose__func__is a pyscript function. That covers a class method called through the class, an instance or a subclass.propertysubclass, which may override__get__or__set__;__getattribute__or__setattr__;@staticmethodalready worked.Testing
test_property_classmethod_match_pythonintests/test_unit_eval.py: 31 sources, each compared with CPython. They cover:property(fget, fset)forms, setters,+=, read-only properties, inheritance and overrides;self, and as alternate constructors;__getattribute__/__setattr__,propertysubclasses, and__getattr__fallbacks.sphinx-build -Wpass on Python 3.14.Docs
Language Limitations now says
@property,@classmethodand@staticmethodwork on methods of a pyscript class, and lists what still doesn't:getattr()/hasattr()on a pyscript property;functools.cached_property;super().prop;__getattribute__or__setattr__.Note
This changes a few lines of
call_funcnext to the PR for #891 (classes andsuper()). If that PR merges first, this one needs a small rebase, and I'm happy to do it.My open #910 and #912 also change
eval.py(#912 addsEvalAttrSet.delattr, next to the newsetattr_async); a small rebase may be needed there too.