Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Inferred return type of a decorated function is incorrect #1852

Open
michitaro opened this issue Dec 25, 2019 · 1 comment
Open

Inferred return type of a decorated function is incorrect #1852

michitaro opened this issue Dec 25, 2019 · 1 comment
Labels
enhancement New feature or request feature: analysis

Comments

@michitaro
Copy link

Inferred return type of a decorated function is incorrect.
(That is the one for the function without the decoration.)

Environment data

  • Language Server version: 0.5.10.0
  • OS and version: macOS 10.15
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda3 Python 3.7.3

Expected behaviour

  • The LS infers a correct return type of a decorated function.

Actual behaviour

  • The LS infers a return type of a decorated function as if the function is not decorated.

Logs

N/A

Code Snippet / Additional lnformation

from typing import Any, Callable


def stringify(f: Callable[..., Any]) -> Callable[..., str]:
    def wrapper(*args) -> str:
        return str(f(*args))
    return wrapper

@stringify
def one() -> int:
    return 1

value = one() # inferred type of `value` by the LS is `int`,
              # but it should be `str`

print(type(value))
# <class 'str'>

Screen Shot 2019-12-25 at 16 52 50

@MikhailArkhipov
Copy link

True, currently analysis does not look into decorators in order to find out possible return type. Also, Callable is not currently handled. #1115 and #535

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feature: analysis
Projects
None yet
Development

No branches or pull requests

2 participants