Skip to content

Fix F811 false positive for overloaded functions from typing-modules#23357

Merged
ntBre merged 3 commits intoastral-sh:mainfrom
kar-ganap:fix/issue-19632
Feb 23, 2026
Merged

Fix F811 false positive for overloaded functions from typing-modules#23357
ntBre merged 3 commits intoastral-sh:mainfrom
kar-ganap:fix/issue-19632

Conversation

@kar-ganap
Copy link
Contributor

Summary

Fixes #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 function definition.

The root cause is in SemanticModel::match_typing_qualified_name: QualifiedName::from_dotted_name splits on dots, so a single-segment module like std still works, but the internal representation stores it differently from what QualifiedName::user_defined produces. Use user_defined instead to match the internal representation consistently.

Test plan

  • Reproduction case: ruff check --select F811 --config ruff.toml temp.py no longer emits false positives for @overload from custom typing-modules
  • cargo test -p ruff_linter -- pyflakes — all 462 tests pass

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

astral-sh-bot bot commented Feb 16, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

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.

Can you add a regression test for this showing that the issue is now resolved?

@kar-ganap
Copy link
Contributor Author

Added the regression test — verifies that @overload from a custom typing-modules entry does not trigger F811. CI should be green. Ready for another look when you have a moment.

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.

Thanks!

@ntBre ntBre added bug Something isn't working rule Implementing or modifying a lint rule labels Feb 23, 2026
@ntBre ntBre enabled auto-merge (squash) February 23, 2026 15:45
@ntBre ntBre merged commit e462c03 into astral-sh:main Feb 23, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Got F811 when indirectly importing overload

2 participants