Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/ty_python_semantic/resources/mdtest/import/conflicts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```py
import a.b

reveal_type(a.b) # revealed: <module 'a.b'>
reveal_type(a.b) # revealed: int
```

`a/__init__.py`:
Expand Down Expand Up @@ -44,8 +44,8 @@ b: int = 42
import a.b
from a import b

reveal_type(b) # revealed: <module 'a.b'>
reveal_type(a.b) # revealed: <module 'a.b'>
reveal_type(b) # revealed: int
reveal_type(a.b) # revealed: int
```

`a/__init__.py`:
Expand Down Expand Up @@ -73,8 +73,8 @@ from a import b
import a.b

# Python would say `int` for `b`
reveal_type(b) # revealed: <module 'a.b'>
reveal_type(a.b) # revealed: <module 'a.b'>
reveal_type(b) # revealed: int
reveal_type(a.b) # revealed: int
```

`a/__init__.py`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ y: int = 2
`main.py`:

```py
from typing import TYPE_CHECKING
from typing import List
from mypackage.conflicted.other1 import x as x1
import mypackage.conflicted.b.c

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ import sub.b
import attr.b

# In the Python interpreter, `attr.b` is Literal[1]
reveal_type(sub.b) # revealed: <module 'sub.b'>
reveal_type(attr.b) # revealed: <module 'attr.b'>
reveal_type(sub.b) # revealed: Literal[1]
reveal_type(attr.b) # revealed: Literal[1]
```

`sub/__init__.py`:
Expand Down
13 changes: 0 additions & 13 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12306,19 +12306,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 <something>,
// 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)
Expand Down
Loading