Fix F811 false positive for overloaded functions from typing-modules#23357
Merged
ntBre merged 3 commits intoastral-sh:mainfrom Feb 23, 2026
Merged
Fix F811 false positive for overloaded functions from typing-modules#23357ntBre merged 3 commits intoastral-sh:mainfrom
ntBre merged 3 commits intoastral-sh:mainfrom
Conversation
Fixes astral-sh#19632. When \`@overload\` is imported from a custom module listed in \`typing-modules\` (e.g., \`from std import overload\`), Ruff fails to recognize it as the \`typing.overload\` decorator and emits false F811 diagnostics for each overloaded definition. The root cause is in \`SemanticModel::match_typing_qualified_name\`: \`QualifiedName::from_dotted_name\` splits on dots, so a module like \`std\` becomes \`["std"]\` — but the semantic model stores it as a single segment \`["std"]\` from \`user_defined\`. Use \`QualifiedName::user_defined\` instead to match the internal representation.
|
ntBre
requested changes
Feb 16, 2026
Contributor
ntBre
left a comment
There was a problem hiding this comment.
Can you add a regression test for this showing that the issue is now resolved?
Contributor
Author
|
Added the regression test — verifies that |
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
Fixes #19632.
When
@overloadis imported from a custom module listed intyping-modules(e.g.,from std import overload), Ruff fails to recognize it as thetyping.overloaddecorator and emits false F811 diagnostics for each overloaded function definition.The root cause is in
SemanticModel::match_typing_qualified_name:QualifiedName::from_dotted_namesplits on dots, so a single-segment module likestdstill works, but the internal representation stores it differently from whatQualifiedName::user_definedproduces. Useuser_definedinstead to match the internal representation consistently.Test plan
ruff check --select F811 --config ruff.toml temp.pyno longer emits false positives for@overloadfrom custom typing-modulescargo test -p ruff_linter -- pyflakes— all 462 tests pass