-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Replaced typing.Self
with typing_extensions.Self
#12744
Conversation
fe1302c
to
e628783
Compare
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.
Can we add some typing assertions about this to prevent a accidental undo of the issue
We have a file in the Testsuite for doing these
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.
Thanks, looks good to me.
The file @RonnyPfannschmidt refers to is testing/typing_checks.py
.
Probably this will not help, because IIUC it should fail as soon as any of the changed modules is imported under Python 3.9, which did not happen. I think we need to add With this: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 938b0bf40..8c7fde3f2 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -26,6 +26,7 @@ repos:
- id: mypy
files: ^(src/|testing/|scripts/)
args: []
+ language_version: "3.8"
additional_dependencies:
- iniconfig>=1.1.0
- attrs>=19.2.0 I get these errors on
I will do this in a separate PR. |
Backport to 8.3.x: 💚 backport PR created✅ Backport PR branch: Backported as #12746 🤖 @patchback |
Fix incorrect Self import from typing instead of typing_extensions. --------- Co-authored-by: Bruno Oliveira <[email protected]> (cherry picked from commit c947145)
Follow up to pytest-dev#12744, this ensures type checking works at the oldest Python version supported by pytest.
Follow up to pytest-dev#12744, this ensures type checking works at the oldest Python version supported by pytest.
Done: #12747 |
Correct, adding tests wouldn't cover new regressions if mypy checks are done against newer versions of Python. Type-checkers should be tested for older versions. |
…947145fbb4aeec810a259b19f70fcb52fd53ad4/pr-12744 [PR #12744/c947145f backport][8.3.x] Replaced `typing.Self` with `typing_extensions.Self`
Follow up to #12744, this ensures type checking works at the oldest Python version supported by pytest.
Follow up to #12744, this ensures type checking works at the oldest Python version supported by pytest. (cherry picked from commit 419bc7a) Co-authored-by: Bruno Oliveira <[email protected]>
Fixes #11916 (comment)
Importing
Self
fromtyping
breaks the return type on Python 3.9 and under. You should be usingfrom typing_extension import Self
instead.For example, the following code:
Will error with
Returning Any from function declared to return "CheckdocsItem | None" [no-any-return]
on 3.8 & 3.9, but pass on 3.10+ Which can only be worked around by disabling the error entirely in mypy, or doing: