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

Incorrect inference of decorated function #2632

Open
apmorton opened this issue Nov 1, 2024 · 0 comments
Open

Incorrect inference of decorated function #2632

apmorton opened this issue Nov 1, 2024 · 0 comments
Labels
decorators Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@apmorton
Copy link

apmorton commented Nov 1, 2024

Using astroid 3.3.5

import astroid

module = astroid.parse(
    """
def decorate(obj=None):
    if obj is None:
        return lambda x: decorate(x)
    if isinstance(obj, property):
        return property()
    return obj


@decorate()
def func() -> str:
    return 'foo'


x = func()
"""
)

func = module.body[1]
print(func)
print(func.inferred()[0])

Astroid incorrectly infers this function as Property.func.

This causes the final line x = func() to emit an error under pylint:

E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)

If you change to:

@decorate
def func() -> str:
    return 'foo'

Astroid correctly infers this as FunctionDef.func.

This is a minimized repro of the error reported here dagster-io/dagster#24009

@jacobtylerwalls jacobtylerwalls added Needs PR This issue is accepted, sufficiently specified and now needs an implementation decorators labels Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decorators Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants