[flake8-pyi] Fix inconsistent handling of forward references for __new__, __enter__, __aenter__ in PYI034#22798
Merged
AlexWaygood merged 2 commits intoastral-sh:mainfrom Jan 22, 2026
Conversation
AlexWaygood
reviewed
Jan 22, 2026
crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI034.py
Outdated
Show resolved
Hide resolved
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI034 | 10 | 10 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+10 -0 violations, +0 -0 fixes in 4 projects; 51 projects unchanged)
apache/superset (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL
+ superset/mcp_service/utils/retry_utils.py:229:9: PYI034 `__enter__` methods in classes like `RetryableOperation` usually return `self` at runtime
freedomofpress/securedrop (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ devops/scripts/verify-mo.py:54:9: PYI034 `__enter__` methods in classes like `CatalogVerifier` usually return `self` at runtime
rotki/rotki (+7 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ rotkehlchen/assets/resolver.py:38:9: PYI034 `__new__` methods in classes like `AssetResolver` usually return `self` at runtime + rotkehlchen/db/drivers/gevent.py:72:9: PYI034 `__enter__` methods in classes like `DBCursor` usually return `self` at runtime + rotkehlchen/db/settings.py:512:9: PYI034 `__new__` methods in classes like `CachedSettings` usually return `self` at runtime + rotkehlchen/globaldb/handler.py:118:9: PYI034 `__new__` methods in classes like `GlobalDBHandler` usually return `self` at runtime + rotkehlchen/history/price.py:82:9: PYI034 `__new__` methods in classes like `PriceHistorian` usually return `self` at runtime + rotkehlchen/inquirer.py:355:9: PYI034 `__new__` methods in classes like `Inquirer` usually return `self` at runtime + rotkehlchen/utils/hexbytes.py:46:9: PYI034 `__new__` methods in classes like `HexBytes` usually return `self` at runtime
scikit-build/scikit-build-core (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ src/scikit_build_core/settings/skbuild_model.py:50:9: PYI034 `__new__` methods in classes like `CMakeSettingsDefine` usually return `self` at runtime
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI034 | 10 | 10 | 0 | 0 | 0 |
Contributor
Author
|
@AlexWaygood not sure what's up with the one job that failed |
Member
|
just GitHub being flaky, I think :-) I'm rerunning it |
AlexWaygood
approved these changes
Jan 22, 2026
Member
AlexWaygood
left a comment
There was a problem hiding this comment.
This is great, thank you. Lots of true positives in the ecosystem report!
flake8-pyi] Fix inconsistent handling of forward references for __new__, __enter__, __aenter__ in PYI034
|
@denyszhak thank you! |
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
Fix PYI034 to detect forward-reference strings for new, enter, and aenter. Previously only iadd handled stringized annotations correctly.
Fixes #22795
Test Plan
Added test case UsesStringizedForwardReferences with all four method types using quoted return annotations. Verified all are now caught.