-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEP 702 (@deprecated): "normal" overloaded methods #18477
Changes from 10 commits
2461eff
1ba5cf1
7f3d73c
a0fcf31
6599d2b
b4a9cd3
2ff8cf1
6757391
cc7a915
c95f936
7522cb8
c758922
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -377,6 +377,179 @@ for i in a: # E: function __main__.A.__iter__ is deprecated: no iteration | |||||||||||
[builtins fixtures/tuple.pyi] | ||||||||||||
|
||||||||||||
|
||||||||||||
[case testDeprecatedOverloadedInstanceMethods] | ||||||||||||
# flags: --enable-error-code=deprecated | ||||||||||||
|
||||||||||||
from typing import Iterator, Union | ||||||||||||
from typing_extensions import deprecated, overload | ||||||||||||
|
||||||||||||
class A: | ||||||||||||
@overload | ||||||||||||
@deprecated("pass `str` instead") | ||||||||||||
def f(self, v: int) -> None: ... | ||||||||||||
@overload | ||||||||||||
def f(self, v: str) -> None: ... | ||||||||||||
def f(self, v: Union[int, str]) -> None: ... | ||||||||||||
|
||||||||||||
@overload | ||||||||||||
def g(self, v: int) -> None: ... | ||||||||||||
@overload | ||||||||||||
@deprecated("pass `int` instead") | ||||||||||||
def g(self, v: str) -> None: ... | ||||||||||||
def g(self, v: Union[int, str]) -> None: ... | ||||||||||||
|
||||||||||||
@overload | ||||||||||||
def h(self, v: int) -> A: ... | ||||||||||||
@overload | ||||||||||||
def h(self, v: str) -> A: ... | ||||||||||||
@deprecated("use `h2` instead") | ||||||||||||
def h(self, v: Union[int, str]) -> A: ... | ||||||||||||
|
||||||||||||
class B(A): ... | ||||||||||||
|
||||||||||||
int_or_str: Union[int, str] | ||||||||||||
|
||||||||||||
a = A() | ||||||||||||
a.f(1) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
a.f("x") | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also test this case:
Suggested change
It should not raise if all is good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not raise a warning, but why do you think it should not? (There is not even a warning for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I made it consistent in c95f936. However, I added the in my opinion missing warnings to the test case, to prevent us from merging this too early by accident. I am curious to hear why you think the current behaviour is correct. (regarding |
||||||||||||
a.f(int_or_str) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
a.g(1) | ||||||||||||
a.g("x") # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
a.g(int_or_str) # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
a.h(1) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
a.h("x") # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
a.h(int_or_str) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
|
||||||||||||
b = B() | ||||||||||||
b.f(1) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
b.f("x") | ||||||||||||
b.f(int_or_str) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
b.g(1) | ||||||||||||
b.g("x") # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
b.g(int_or_str) # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
b.h(1) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
b.h("x") # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
b.h(int_or_str) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
|
||||||||||||
[builtins fixtures/tuple.pyi] | ||||||||||||
|
||||||||||||
|
||||||||||||
[case testDeprecatedOverloadedClassMethods] | ||||||||||||
# flags: --enable-error-code=deprecated | ||||||||||||
|
||||||||||||
from typing import Iterator, Union | ||||||||||||
from typing_extensions import deprecated, overload | ||||||||||||
|
||||||||||||
class A: | ||||||||||||
@overload | ||||||||||||
@classmethod | ||||||||||||
@deprecated("pass `str` instead") | ||||||||||||
def f(cls, v: int) -> None: ... | ||||||||||||
@overload | ||||||||||||
@classmethod | ||||||||||||
def f(cls, v: str) -> None: ... | ||||||||||||
@classmethod | ||||||||||||
def f(cls, v: Union[int, str]) -> None: ... | ||||||||||||
|
||||||||||||
@overload | ||||||||||||
@classmethod | ||||||||||||
def g(cls, v: int) -> None: ... | ||||||||||||
@overload | ||||||||||||
@classmethod | ||||||||||||
@deprecated("pass `int` instead") | ||||||||||||
def g(cls, v: str) -> None: ... | ||||||||||||
@classmethod | ||||||||||||
def g(cls, v: Union[int, str]) -> None: ... | ||||||||||||
|
||||||||||||
@overload | ||||||||||||
@classmethod | ||||||||||||
def h(cls, v: int) -> A: ... | ||||||||||||
@overload | ||||||||||||
@classmethod | ||||||||||||
def h(cls, v: str) -> A: ... | ||||||||||||
@deprecated("use `h2` instead") | ||||||||||||
@classmethod | ||||||||||||
def h(cls, v: Union[int, str]) -> A: ... | ||||||||||||
|
||||||||||||
class B(A): ... | ||||||||||||
sobolevn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
a = A() | ||||||||||||
a.f(1) # E: overload def (cls: type[__main__.A], v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
a.f("x") | ||||||||||||
a.g(1) | ||||||||||||
a.g("x") # E: overload def (cls: type[__main__.A], v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
a.h(1) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
a.h("x") # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
|
||||||||||||
b = B() | ||||||||||||
b.f(1) # E: overload def (cls: type[__main__.A], v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
b.f("x") | ||||||||||||
b.g(1) | ||||||||||||
b.g("x") # E: overload def (cls: type[__main__.A], v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
b.h(1) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
b.h("x") # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
|
||||||||||||
[builtins fixtures/tuple.pyi] | ||||||||||||
|
||||||||||||
|
||||||||||||
[case testDeprecatedOverloadedStaticMethods] | ||||||||||||
# flags: --enable-error-code=deprecated | ||||||||||||
|
||||||||||||
from typing import Iterator, Union | ||||||||||||
from typing_extensions import deprecated, overload | ||||||||||||
|
||||||||||||
class A: | ||||||||||||
@overload | ||||||||||||
@staticmethod | ||||||||||||
@deprecated("pass `str` instead") | ||||||||||||
def f(v: int) -> None: ... | ||||||||||||
@overload | ||||||||||||
@staticmethod | ||||||||||||
def f(v: str) -> None: ... | ||||||||||||
@staticmethod | ||||||||||||
def f(v: Union[int, str]) -> None: ... | ||||||||||||
|
||||||||||||
@overload | ||||||||||||
@staticmethod | ||||||||||||
def g(v: int) -> None: ... | ||||||||||||
@overload | ||||||||||||
@staticmethod | ||||||||||||
@deprecated("pass `int` instead") | ||||||||||||
def g(v: str) -> None: ... | ||||||||||||
@staticmethod | ||||||||||||
def g(v: Union[int, str]) -> None: ... | ||||||||||||
|
||||||||||||
@overload | ||||||||||||
@staticmethod | ||||||||||||
def h(v: int) -> A: ... | ||||||||||||
@overload | ||||||||||||
@staticmethod | ||||||||||||
def h(v: str) -> A: ... | ||||||||||||
@deprecated("use `h2` instead") | ||||||||||||
@staticmethod | ||||||||||||
def h(v: Union[int, str]) -> A: ... | ||||||||||||
|
||||||||||||
class B(A): ... | ||||||||||||
|
||||||||||||
a = A() | ||||||||||||
a.f(1) # E: overload def (v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
a.f("x") | ||||||||||||
a.g(1) | ||||||||||||
a.g("x") # E: overload def (v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
a.h(1) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
a.h("x") # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
|
||||||||||||
b = B() | ||||||||||||
b.f(1) # E: overload def (v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead | ||||||||||||
b.f("x") | ||||||||||||
b.g(1) | ||||||||||||
b.g("x") # E: overload def (v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead | ||||||||||||
b.h(1) # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
b.h("x") # E: function __main__.A.h is deprecated: use `h2` instead | ||||||||||||
|
||||||||||||
[builtins fixtures/classmethod.pyi] | ||||||||||||
|
||||||||||||
|
||||||||||||
[case testDeprecatedOverloadedSpecialMethods] | ||||||||||||
# flags: --enable-error-code=deprecated | ||||||||||||
|
||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we can use
object_type.type.get(member)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I adjusted it.