Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flake8-pyi] Fix inconsistent handling of forward references for __new__, __enter__, __aenter__ in PYI034#22798

Merged
AlexWaygood merged 2 commits intoastral-sh:mainfrom
denyszhak:fix/inconsistent-handling-of-forward-references
Jan 22, 2026
Merged

[flake8-pyi] Fix inconsistent handling of forward references for __new__, __enter__, __aenter__ in PYI034#22798
AlexWaygood merged 2 commits intoastral-sh:mainfrom
denyszhak:fix/inconsistent-handling-of-forward-references

Conversation

@denyszhak
Copy link
Contributor

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.

Copy link
Member

@AlexWaygood AlexWaygood 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!

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 22, 2026

ruff-ecosystem results

Linter (stable)

ℹ️ 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 --no-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)

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

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

+ 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

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

@denyszhak denyszhak requested a review from AlexWaygood January 22, 2026 12:08
@denyszhak
Copy link
Contributor Author

@AlexWaygood not sure what's up with the one job that failed

@AlexWaygood
Copy link
Member

just GitHub being flaky, I think :-) I'm rerunning it

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

This is great, thank you. Lots of true positives in the ecosystem report!

@AlexWaygood AlexWaygood changed the title fix: inconsistent handling of forward references for __new__, __enter__, __aenter__ [flake8-pyi] Fix inconsistent handling of forward references for __new__, __enter__, __aenter__ in PYI034 Jan 22, 2026
@AlexWaygood AlexWaygood merged commit ceb876b into astral-sh:main Jan 22, 2026
67 of 68 checks passed
@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Jan 22, 2026
@vertti
Copy link

vertti commented Jan 22, 2026

@denyszhak thank you!

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.

PYI034: Inconsistent handling of forward-reference strings for __new__ and __enter__

3 participants