-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: report @deprecated() on non-overloaded class constructors
#20104
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
0332484
d497f37
53622b1
39cd5f9
a473e52
8f08c60
b0ffd6b
c954f78
00897ab
3b7b986
4b42ea6
9e49aa1
4be62c6
79d0cb0
5302af3
d595948
c7c580c
f02dc8c
9cfdf7a
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -315,18 +315,51 @@ class E: ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [builtins fixtures/tuple.pyi] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [case testDeprecatedClassInitMethod] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [case testDeprecatedClassConstructor] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bzoracler marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # flags: --enable-error-code=deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing_extensions import deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @deprecated("use C2 instead") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class C: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @deprecated("call `make_c()` instead") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. Could you add a similar test (if there isn't one) in incremental mode? 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. Addressed in 5302af3 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def make_c(cls) -> C: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c: C # E: class __main__.C is deprecated: use C2 instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C() # E: class __main__.C is deprecated: use C2 instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C.__init__(c) # E: class __main__.C is deprecated: use C2 instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C() # E: function __main__.C.__init__ is deprecated: call `make_c()` instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bzoracler marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class D: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @deprecated("call `make_d()` instead") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __new__(cls) -> D: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def make_d(cls) -> D: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| D() # E: function __main__.D.__new__ is deprecated: call `make_d()` instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [builtins fixtures/tuple.pyi] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [case testDeprecatedSuperClassConstructor] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # flags: --enable-error-code=deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing_extensions import deprecated, Self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class A: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @deprecated("call `self.initialise()` instead") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def initialise(self) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. Could you also check 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. Committed 4be62c6 to address this...well kind of. I did not add checks for
See mypy Playground. In any case, this is still simply testing for deprecation warnings upon attribute access (the attribute just happens to be a class constructor method, and we can't mypy/test-data/unit/check-deprecated.test Lines 584 to 614 in 054f721
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class B(A): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super().__init__() # E: function __main__.A.__init__ is deprecated: call `self.initialise()` instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class C: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @deprecated("call `object.__new__(cls)` instead") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __new__(cls) -> Self: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class D(C): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __new__(cls) -> Self: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return super().__new__(cls) # E: function __main__.C.__new__ is deprecated: call `object.__new__(cls)` instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [builtins fixtures/tuple.pyi] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.