PEP 702 (@deprecated): consider all possible type positions#17926
Conversation
This comment has been minimized.
This comment has been minimized.
|
On second thought: def visit_instance(self, t: Instance) -> None:
super().visit_instance(t)
if not (
isinstance(defn := self.context, FuncDef)
and defn.info and
(t.type.fullname == defn.info.fullname)
):
self.typechecker.check_deprecated(t.type, self.context) |
|
After a bit of experimenting, I think extending |
sobolevn
left a comment
There was a problem hiding this comment.
Generally looks good to me. But, maybe we should simplify this to ignore_self? And just ignore first args in class / instance methods?
|
I think the whole visitor should be replaced with a single check in Another thought is that we need to update the @tyralla Could you please re-purpose this PR for the above two things? |
|
Note btw what I say above may require moving around some existing code for emitting error messages, since you can't import |
Thanks for the review, @sobolevn. Could you explain why you suggest simplifying? I see now that a reference to the relevant class (
And thanks for the suggestion, @ilevkivskyi. |
Or a function, of course. |
… for the current test suite, which we still need to extend.)
This comment has been minimized.
This comment has been minimized.
|
As an alternative suggestion, I generalised The Mypy diff for I did not investigate why the deprecation warnings were raised when executing the Python evaluation suite. Whether we proceed this way or via extending |
This comment has been minimized.
This comment has been minimized.
…e-grained tests (problem: `y: b.D`)
I did so. There is a problem for: import b
y: b.D |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I could fix the I will add more tests to Regarding the Python evaluation suite, I am stuck. Adding |
|
I filed a PR to typeshed, added a few more tests (all passed without further effort), and renamed this PR. So, if the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
According to the discussion in #18007, I silenced |
|
TBH I don't like the idea of essentially traversing the whole tree twice, even as a temporary state. The deprecation check for types should be in |
To me, it appears cleaner (the separation and leaving everything in
Okay, I will try it this way. (I need to access the import definitions to suppress repeated notes for types that have already been reported as deprecated at a |
…hod `TypeAnalyzer.check_and_warn_deprecated` (module `typeanal`).
for more information, see https://pre-commit.ci
|
Diff from mypy_primer, showing the effect of this PR on open source code: Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/context/base.py:48: note: class alluka._context.BasicContext is deprecated: Use Context or CachingContext [deprecated]
+ tanjun/context/autocomplete.py:54: note: class alluka._context.BasicContext is deprecated: Use Context or CachingContext [deprecated]
core (https://github.com/home-assistant/core)
+ homeassistant/runner.py:84: note: class asyncio.unix_events.AbstractChildWatcher is deprecated: Deprecated as of Python 3.12; will be removed in Python 3.14 [deprecated]
|
|
I moved the deprecation check to |
This pull request generalises #17899.
Initially, it started with extending #17899 to function signatures only, as can be seen from the following initial comments and the subsequent discussions.
@ilevkivskyi
This is part two of the checker.py chase.
I had to extend
InstanceDeprecatedVisitorso that it refrains from reporting thatselfin the signature of a deprecated class' method refers to this deprecated class. This seems to suggest that a strictly uniform handling for all possible type positions might not be possible. Do you think the same?However, searching for more central locations to apply
InstanceDeprecatedVisitoris certainly a good idea. I can try it in this or the next PR, as you prefer.