From b4887e77ba28ee5e7fe0fe0e22556ce6868f18f8 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Sat, 13 Dec 2025 15:11:31 -0500 Subject: [PATCH] uniformly weak imports --- .../resources/mdtest/import/conflicts.md | 10 +++++----- .../resources/mdtest/import/tracking.md | 4 ++-- crates/ty_python_semantic/src/types.rs | 13 ------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/import/conflicts.md b/crates/ty_python_semantic/resources/mdtest/import/conflicts.md index 353166220f..1ebf8b7e21 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/conflicts.md +++ b/crates/ty_python_semantic/resources/mdtest/import/conflicts.md @@ -5,7 +5,7 @@ ```py import a.b -reveal_type(a.b) # revealed: +reveal_type(a.b) # revealed: int ``` `a/__init__.py`: @@ -44,8 +44,8 @@ b: int = 42 import a.b from a import b -reveal_type(b) # revealed: -reveal_type(a.b) # revealed: +reveal_type(b) # revealed: int +reveal_type(a.b) # revealed: int ``` `a/__init__.py`: @@ -73,8 +73,8 @@ from a import b import a.b # Python would say `int` for `b` -reveal_type(b) # revealed: -reveal_type(a.b) # revealed: +reveal_type(b) # revealed: int +reveal_type(a.b) # revealed: int ``` `a/__init__.py`: diff --git a/crates/ty_python_semantic/resources/mdtest/import/tracking.md b/crates/ty_python_semantic/resources/mdtest/import/tracking.md index 16c2473a7e..f8dee3a9d5 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/tracking.md +++ b/crates/ty_python_semantic/resources/mdtest/import/tracking.md @@ -89,8 +89,8 @@ import sub.b import attr.b # In the Python interpreter, `attr.b` is Literal[1] -reveal_type(sub.b) # revealed: -reveal_type(attr.b) # revealed: +reveal_type(sub.b) # revealed: Literal[1] +reveal_type(attr.b) # revealed: Literal[1] ``` `sub/__init__.py`: diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 17eaacb52f..96f9f35659 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -13301,19 +13301,6 @@ impl<'db> ModuleLiteralType<'db> { submodule_type = self.resolve_submodule(db, name); } - // if we're in a module `foo` and `foo` contains `import a.b`, - // and the package `a` has a submodule `b`, we assume that the - // attribute access `a.b` inside `foo` will resolve to the submodule - // `a.b` *even if* `a/__init__.py` also defines a symbol `b` (e.g. `b = 42`). - // This is a heuristic, but it's almost certainly what will actually happen - // at runtime. However, if `foo` only contains `from a.b import , - // we prioritise the `b` attribute in `a/__init__.py` over the submodule `a.b`. - if available_submodule_kind == Some(ImportKind::Import) - && let Some(submodule) = submodule_type - { - return Place::bound(submodule).into(); - } - let place_and_qualifiers = self .module(db) .file(db)