Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.11 decorator detection bug #49

Closed
alexmojaki opened this issue Sep 20, 2022 · 0 comments · Fixed by #50
Closed

3.11 decorator detection bug #49

alexmojaki opened this issue Sep 20, 2022 · 0 comments · Fixed by #50
Assignees

Comments

@alexmojaki
Copy link
Owner

import inspect

import executing

frame = inspect.currentframe()


class Tester:
    def __call__(self, f):
        deco(f)


tester = Tester()


def deco(f):
    assert f.__name__ == 'foo'
    ex = executing.Source.executing(frame)
    print(f"{ex.node = }\n{ex.decorator = }\n")


for d in [deco, tester]:
    @d
    def foo():
        pass

3.10 output:

ex.node = <ast.FunctionDef object at 0x7f9c7e65b1c0>
ex.decorator = <ast.Name object at 0x7f9c7e65a2f0>

ex.node = <ast.FunctionDef object at 0x7f9c7e65b1c0>
ex.decorator = <ast.Name object at 0x7f9c7e65a2f0>

3.11 output:

ex.node = <ast.Name object at 0x7fd9fe5a96f0>
ex.decorator = None

ex.node = <ast.FunctionDef object at 0x7fd9fe5a9780>
ex.decorator = <ast.Name object at 0x7fd9fe5a96f0>

Somehow, the decorator is only detected when it's an object with __call__. When it's just a function, executing sets decorator to None and node to the decorator instead of the function definition. This is REALLY weird.

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 a pull request may close this issue.

2 participants