[pyupgrade] Fix handling of typing.{io,re} (UP035)#23131
Merged
ntBre merged 1 commit intoastral-sh:mainfrom Feb 19, 2026
Merged
[pyupgrade] Fix handling of typing.{io,re} (UP035)#23131ntBre merged 1 commit intoastral-sh:mainfrom
pyupgrade] Fix handling of typing.{io,re} (UP035)#23131ntBre merged 1 commit intoastral-sh:mainfrom
Conversation
Back in Python 3.5, the docs referred to `typing.io` as the primary location for `IO`, `TextIO`, and `BinaryIO` and `typing.re` as the primary location for `Pattern` and `Match`: - https://docs.python.org/3.5/library/typing.html#typing.io - https://docs.python.org/3.5/library/typing.html#typing.re In Python 3.6, reference to `typing.io` and `typing.re` disappeared and these types were importable directly from `typing`: - https://docs.python.org/3.6/library/typing.html#typing.IO - https://docs.python.org/3.6/library/typing.html#typing.Pattern In Python 3.9, the `typing.io` and `typing.re` namespaces were deprecated pending removal in Python 3.12. In addition, `typing.Pattern` and `typing.Match` were deprecated in favour of `re.Pattern` and `re.Match`: - https://docs.python.org/3.9/library/typing.html#typing.IO - https://docs.python.org/3.9/library/typing.html#typing.Pattern Although interestingly it implies that the deprecation of the namespaces was from Python 3.8. The pending removal version for the namespaces was updated from 3.12 to 3.13 as the deprecation warning was only in place from 3.11 - that update was backported through 3.10: - https://docs.python.org/3.10/library/typing.html#typing.IO - https://docs.python.org/3.10/library/typing.html#typing.Pattern The namespaces were removed in Python 3.13: - https://docs.python.org/3.13/library/typing.html#typing.IO - https://docs.python.org/3.13/library/typing.html#typing.Pattern On this basis, it seems we could update `UP035` for the `typing.io` and `typing.re` namespaces to target as far back as Python 3.6 as they weren't even mentioned in the docs for Python 3.6 to 3.8 and only mentioned again when soft deprecated in Python 3.9. The versions of these types in the main `typing` module have been available the whole time. As ruff only targets 3.7+, let's go for 3.7.
|
ntBre
approved these changes
Feb 19, 2026
Contributor
ntBre
left a comment
There was a problem hiding this comment.
Thank you! Sorry for the delay, this makes sense to me, and I think it's okay to skip preview since the ecosystem impact seems (hopefully!) limited even though it expands the rule's scope a bit.
knutwannheden
pushed a commit
to openrewrite/ruff
that referenced
this pull request
Feb 20, 2026
…3131) ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Back in Python 3.5, the docs referred to `typing.io` as the primary location for `IO`, `TextIO`, and `BinaryIO` and `typing.re` as the primary location for `Pattern` and `Match`: - https://docs.python.org/3.5/library/typing.html#typing.io - https://docs.python.org/3.5/library/typing.html#typing.re In Python 3.6, reference to `typing.io` and `typing.re` disappeared and these types were importable directly from `typing`: - https://docs.python.org/3.6/library/typing.html#typing.IO - https://docs.python.org/3.6/library/typing.html#typing.Pattern In Python 3.9, the `typing.io` and `typing.re` namespaces were deprecated pending removal in Python 3.12. In addition, `typing.Pattern` and `typing.Match` were deprecated in favour of `re.Pattern` and `re.Match`: - https://docs.python.org/3.9/library/typing.html#typing.IO - https://docs.python.org/3.9/library/typing.html#typing.Pattern Although interestingly it implies that the deprecation of the namespaces was from Python 3.8. The pending removal version for the namespaces was updated from 3.12 to 3.13 as the deprecation warning was only in place from 3.11 - that update was backported through 3.10: - https://docs.python.org/3.10/library/typing.html#typing.IO - https://docs.python.org/3.10/library/typing.html#typing.Pattern The namespaces were removed in Python 3.13: - https://docs.python.org/3.13/library/typing.html#typing.IO - https://docs.python.org/3.13/library/typing.html#typing.Pattern On this basis, it seems we could update `UP035` for the `typing.io` and `typing.re` namespaces to target as far back as Python 3.6 as they weren't even mentioned in the docs for Python 3.6 to 3.8 and only mentioned again when soft deprecated in Python 3.9. The versions of these types in the main `typing` module have been available the whole time. As ruff only targets 3.7+, let's go for 3.7. ## Test Plan <!-- How was it tested? --> Updated snapshots.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Back in Python 3.5, the docs referred to
typing.ioas the primary location forIO,TextIO, andBinaryIOandtyping.reas the primary location forPatternandMatch:In Python 3.6, reference to
typing.ioandtyping.redisappeared and these types were importable directly fromtyping:In Python 3.9, the
typing.ioandtyping.renamespaces were deprecated pending removal in Python 3.12. In addition,typing.Patternandtyping.Matchwere deprecated in favour ofre.Patternandre.Match:Although interestingly it implies that the deprecation of the namespaces was from Python 3.8.
The pending removal version for the namespaces was updated from 3.12 to 3.13 as the deprecation warning was only in place from 3.11 - that update was backported through 3.10:
The namespaces were removed in Python 3.13:
On this basis, it seems we could update
UP035for thetyping.ioandtyping.renamespaces to target as far back as Python 3.6 as they weren't even mentioned in the docs for Python 3.6 to 3.8 and only mentioned again when soft deprecated in Python 3.9. The versions of these types in the maintypingmodule have been available the whole time. As ruff only targets 3.7+, let's go for 3.7.Test Plan
Updated snapshots.