Skip to content

Incorrect inference of decorated function #2632

Open
@apmorton

Description

@apmorton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs PRThis issue is accepted, sufficiently specified and now needs an implementationdecorators

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions