Replaced typing.Self with typing_extensions.Self#12744
Replaced typing.Self with typing_extensions.Self#12744nicoddemus merged 2 commits intopytest-dev:mainfrom Avasam:typing_extensions-Self
typing.Self with typing_extensions.Self#12744Conversation
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
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
bluetech
left a comment
There was a problem hiding this comment.
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.0I 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 <bruno@soliv.dev> (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.
Fixes #11916 (comment)
Importing
Selffromtypingbreaks the return type on Python 3.9 and under. You should be usingfrom typing_extension import Selfinstead.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: