Skip to content

[pyupgrade] Fix handling of typing.{io,re} (UP035)#23131

Merged
ntBre merged 1 commit intoastral-sh:mainfrom
ngnpope:ngnpope/up035-fix-typing-io-re
Feb 19, 2026
Merged

[pyupgrade] Fix handling of typing.{io,re} (UP035)#23131
ntBre merged 1 commit intoastral-sh:mainfrom
ngnpope:ngnpope/up035-fix-typing-io-re

Conversation

@ngnpope
Copy link
Contributor

@ngnpope ngnpope commented Feb 6, 2026

Summary

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:

In Python 3.6, reference to typing.io and typing.re disappeared and these types were importable directly from typing:

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:

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 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

Updated snapshots.

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.
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 6, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ngnpope ngnpope marked this pull request as ready for review February 6, 2026 22:19
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ntBre ntBre added the rule Implementing or modifying a lint rule label Feb 19, 2026
@ntBre ntBre merged commit 410902f into astral-sh:main Feb 19, 2026
43 checks passed
@ngnpope ngnpope deleted the ngnpope/up035-fix-typing-io-re branch February 19, 2026 20:46
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants