How should `warnings.deprecated` be handled with `typing.overload`?

PEP 702 introduced warnings.deprecated, and gives an example to deprecate a specific overload:

@deprecated("Only str will be allowed")
def foo(x: int) -> str: ...
def foo(x: str) -> str: ...

I am encountering a function that is deprecated and includes two overloads:

def validate_arguments(func: None = None, *, config: 'ConfigType' = None) -> Callable[['AnyCallableT'], 'AnyCallableT']:

def validate_arguments(func: 'AnyCallableT') -> 'AnyCallableT':

    'The `validate_arguments` method is deprecated; use `validate_call` instead.',
def validate_arguments(func: Optional['AnyCallableT'] = None, *, config: 'ConfigType' = None) -> Any:

To be clear, it is the function that is deprecated (not one of the overloads). How should I treat this case?
Add the deprecated decorator on both overloads?

I’m asking this from a typing perspective, as pyright currently only consider the function as being deprecated if called:


Whereas functions without overloads are marked as being deprecated even without calling them:

What you did is correct; I think pyright should consider the whole function as deprecated if the implementation is decorated.

Please open an issue in the pyright issue tracker.

Thanks to both of you.

Thanks for reporting this. It will be addressed in next week’s pyright release.