pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

Add EvalFuncVar binding via descriptor and drop manual rebinding

Open dmamelin opened this issue 3 weeks ago • 2 comments

Looking into #787 I found that Enum overrides __dir__, so dir(inst) inside call_func doesn’t show the method. I went deep into MRO, inspect, etc., but the actual fix turned out to be much simpler: descriptors solve this problem. CPython implementation

A quick search shows that __dir__ is rarely overridden, but this PR may also affect other class-related issues in Pyscript - I just don’t know which ones yet :)

The logic for creating EvalFuncVarClassInst has also changed. Previously, an EvalFuncVarClassInst was created for every available EvalFuncVar method when the instance was constructed. Now, no EvalFuncVarClassInst objects are created during instance construction; instead, a new EvalFuncVarClassInst is created on each access to an EvalFuncVar.

class Test:
    def a(self):
        pass

    def b(self):
        pass

def old():
    test = Test()  # AstEval.call_func: create EvalFuncVarClassInst for a() and b()
    test.a()       # use existing EvalFuncVarClassInst
    test.a()       # use existing EvalFuncVarClassInst

def new():
    test = Test()  # AstEval.call_func: _NO_ EvalFuncVarClassInst created
    test.a()       # create EvalFuncVarClassInst and call it
    test.a()       # create a new EvalFuncVarClassInst and call it
    b = test.a     # create EvalFuncVarClassInst
    b()            # call the existing EvalFuncVarClassInst

dmamelin avatar Dec 11 '25 01:12 dmamelin

The test failure is not related to the modified code.

dmamelin avatar Dec 11 '25 01:12 dmamelin

Hmmm, that's a weird error. I notice it's running the tests using python 3.13.11. My last commit 2 days ran tests with python 3.13.9. Is it some issue with python 3.13.11's modules?

pytest is loading pycares 5.0.0 which was released... today. Yikes - not great to be on the bleeding edge for running tests...

craigbarratt avatar Dec 11 '25 03:12 craigbarratt

https://github.com/aio-libs/aiodns/issues/214 Waiting for Home Assistant 2025.12.3 and pytest-homeassistant-custom-component==0.13.301.

dmamelin avatar Dec 12 '25 14:12 dmamelin

Thanks for the PR. I forced pycares < 5.0.0 in the previous commit, and it now passes all the tests after merging.

craigbarratt avatar Dec 13 '25 00:12 craigbarratt