-
Notifications
You must be signed in to change notification settings - Fork 238
Open
Open
Copy link
Labels
needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.An issue where it's not clear whether there is a bug or we are behaving as expected.
Description
Describe the Bug
Decorating a fully typed function with an untyped decorator can make the function effectively untyped. Example:
from typing import reveal_type
def decorate(f):
def wrapper(x):
return f(x)
return wrapper
@decorate
def f(x: int) -> str:
return str(x)
reveal_type(f) # revealed type: (x: Unknown) -> Unknown # :(
Mypy and pyright deal with this problem in different ways:
mypyhas adisallow-untyped-decoratorssetting that emits an error when a typed function is decorated with an untyped decorator playgroundpyrightpreserves the original signature when the decorator is untyped playground
I'm leaning toward the mypy approach: it's a smaller change to how we handle decorators, a new unannotated-decorator error kind would fit in nicely with our existing unannotated-{attribute,parameter,return} error kinds, and what pyright does is technically unsafe (although it's a reasonable assumption to make in practice). On the other hand, pyright's behavior seems better for IDE/codenav.
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Metadata
Metadata
Assignees
Labels
needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.An issue where it's not clear whether there is a bug or we are behaving as expected.