Calling pep702 deprecated directly #7456
-
This is mostly a question of the expected behaviour. I have been renaming a some functions as a part of a refactor but want to retain the original function names as deprecated aliases using PEP702 decorators. Imagine that I have the following function: def function_a() -> str:
return "function_a_output" I can now see two obvious ways of creating a deprecated alias from typing_extensions import deprecated
@deprecated("Use function_a")
def function_b() -> str:
return function_a() or from typing_extensions import deprecated
function_b = deprecated("Use function_a")(function_a) Both forms will work correctly at runtime calling the function with a deprecation warning and returning the expected result. However, the second form (directly passing the function to the decorator) does not trigger a pyright warning at the site of function execution. My question is therefor. Is this expected? Is it mean to be supported to call the decorator directly? In some cases this would be preferable to me as I can directly copy a function with a different name avoiding to replicate the signature in an alias but perhaps I am overlooking something. Tested in VSCode with the latest pylance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The current behavior is intended. PEP 702 indicates that |
Beta Was this translation helpful? Give feedback.
The current behavior is intended. PEP 702 indicates that
deprecated
is intended to be used as a decorator. If you use it in other ways (not as a decorator), it may work at runtime, but type checkers and language servers will not honor it.