Skip to content

Conversation

@dmamelin
Copy link
Contributor

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
Copy link
Contributor Author

The test failure is not related to the modified code.

@craigbarratt
Copy link
Member

craigbarratt commented Dec 11, 2025

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...

@dmamelin
Copy link
Contributor Author

dmamelin commented Dec 12, 2025

aio-libs/aiodns#214
Waiting for Home Assistant 2025.12.3 and pytest-homeassistant-custom-component==0.13.301.

@craigbarratt craigbarratt merged commit 7008ef3 into custom-components:master Dec 13, 2025
5 of 6 checks passed
@craigbarratt
Copy link
Member

craigbarratt commented Dec 13, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants