PyUpgrade rule UP007 does not work on forward reference string types
- Dominant language
- Rust
- Stars
- 49.7k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 458
Description
Keywords: forward reference, pyupgrade, UP007
Python 3.12, also 3.10
Ruff 0.6.1, also 0.5.7
Command: `ruff check .`
Code:
Python file
```py
x: Optional['Something'] # expect UP007 to trigger here -> x: 'Something | None'
y: Union[int, 'Something'] # expect UP007 to trigger here -> y: 'Something | int'
x2: Optional[Something] # correctly caught by UP007
y2: Union[int, Something] # correctly caught by UP007
class Something:
pass
```
pyproject.toml
```toml
[project]
# As long as this is >=3.10 or any subset, like ==3.10, this bug will occur.
requires-python = ">=3.12"
[tool.ruff.lint]
extend-select = ["UP"]
extend-safe-fixes = ["UP007"]
```
Contributor guide
Research direction
The report provides a minimal Python example and pyproject.toml configuration; start by running `ruff check .` with UP007 enabled. Trace UP007's handling of quoted forward references and add regression coverage; done means both string-reference cases are converted as shown while the existing unquoted cases remain covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100