ruff
4aca9b91 - [red-knot] consider imports to be declarations (#13398)

Comment changes are shownComment changes are hidden
Commit
290 days ago
[red-knot] consider imports to be declarations (#13398) I noticed that this pattern sometimes occurs in typeshed: ``` if ...: from foo import bar else: def bar(): ... ``` If we have the rule that symbols with declarations only use declarations for the public type, then this ends up resolving as `Unknown | Literal[bar]`, because we didn't consider the import to be a declaration. I think the most straightforward thing here is to also consider imports as declarations. The same rationale applies as for function and class definitions: if you shadow an import, you should have to explicitly shadow with an annotation, rather than just doing it implicitly/accidentally. We may also ultimately need to re-evaluate the rule that public type considers only declarations, if there are declarations.
Author
Parents
  • crates/red_knot_python_semantic/src
    • semantic_index
      • File
        definition.rs
    • types
      • File
        infer.rs