Skip to content

Type changes in decorators are not detected #2578

Open

Description

When a decorator changes the return type of a function, that change is not detected.

Steps to reproduce

from typing import Callable
from functools import wraps

def cast_to_str(func) -> Callable[..., str]:
    @wraps(func)
    def wrapper(*args, **kwargs):
        return str(func(*args, **kwargs))
    return wrapper

@cast_to_str
def get_num() -> int:
    return 5

get_num().strip()
# [no-member] Instance of 'int' has no 'strip' member 

Current behavior

Return type of decorated function is set by the function declaration

Expected behavior

Return type of the function set by decorator

pylint --version output

pylint 2.1.1
astroid 2.0.4
Python 3.6.5 (default, May 14 2018, 11:01:09)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]

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

Metadata

Assignees

No one assigned

    Labels

    DecoratorsFalse Negative 🦋No message is emitted but something is wrong with the codeHigh effort 🏋Difficult solution or problem to solveNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationinference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions