-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add provisional support for PEP 702 (marking classes and functions as deprecated) #4456
Comments
This will be included in the next release. Note: @JelleZijlstra |
Thanks as always for your fast work! Let me know if the implementation leads to any feedback about the PEP. I will also amend the PEP to note the pyright implementation. |
Oh, I forgot to mention that this feature will not work at runtime until the |
This is included in pyright 1.1.289, which I just published. It will also be included in a future release of pylance. |
@FeeeeK, this was an oversight. The implementation doesn't currently handle deprecated constructors. This will be addressed in the next release. |
…ting a class. This addresses #4456.
@erictraut It looks like 1.1.373 supports deprecated from __future__ import annotations
# pyright: strict
from typing import (
Union,
overload,
)
from typing_extensions import (
Self,
deprecated,
)
class ClassWithInit:
@overload
def __init__(self, value: int, /) -> None: ...
@deprecated("passing strings is deprecated")
@overload
def __init__(self, value: str, /) -> None: ...
def __init__(self, value: Union[int, str], /) -> None:
pass
class ClassWithNew:
@overload
def __new__(cls, value: int, /) -> Self: ...
@deprecated("passing strings is deprecated")
@overload
def __new__(cls, value: str, /) -> Self: ...
def __new__(cls, value: Union[int, str], /) -> Self:
return super().__new__(cls)
ClassWithInit(42) # no error, as expected
ClassWithInit('forty-two') # "The constructor for class "ClassWithInit" is deprecated"
ClassWithNew(42) # no error, as expected
ClassWithNew('forty-two') # no error (expected: similar error to above) |
Could you please file a new bug so this doesn't get lost? |
Hopefully this will do the trick: #8574 |
See https://peps.python.org/pep-0702/ for details.
The text was updated successfully, but these errors were encountered: