-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added follow import tests and one more example to infer numbers
- Loading branch information
Showing
3 changed files
with
140 additions
and
224 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
crates/red_knot_python_semantic/resources/mdtest/imports.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Follow imports | ||
|
||
## Classes | ||
|
||
We can follow import to class: | ||
|
||
````markdown | ||
```py path=a.py | ||
from b import C as D; E = D | ||
reveal_type(E) # revealed: Literal[C] | ||
``` | ||
|
||
```py path=b.py | ||
class C: pass | ||
``` | ||
```` | ||
|
||
## Relative | ||
|
||
Track that non-existent relative imports resolve to `Unknown`: | ||
````markdown | ||
```py path=package1/__init__.py | ||
``` | ||
|
||
```py path=package1/bar.py | ||
from .foo import X # error: [unresolved-import] | ||
reveal_type(X) # revealed: Unknown | ||
``` | ||
```` | ||
|
||
Follow relative imports: | ||
|
||
````markdown | ||
```py path=package2/__init__.py | ||
``` | ||
|
||
```py path=package2/foo.py | ||
X = 42 | ||
``` | ||
|
||
```py path=package2/bar.py | ||
from .foo import X | ||
reveal_type(X) # revealed: Literal[42] | ||
``` | ||
```` | ||
|
||
We can also follow dotted relative imports: | ||
|
||
````markdown | ||
```py path=package3/__init__.py | ||
``` | ||
|
||
```py path=package3/foo/bar/baz.py | ||
X = 42 | ||
``` | ||
|
||
```py path=package3/bar.py | ||
from .foo.bar.baz import X | ||
reveal_type(X) # revealed: Literal[42] | ||
``` | ||
```` | ||
|
||
Follow relative import bare to package: | ||
|
||
````markdown | ||
```py path=package4/__init__.py | ||
X = 42 | ||
``` | ||
|
||
```py path=package4/bar.py | ||
from . import X | ||
reveal_type(X) # revealed: Literal[42] | ||
``` | ||
```` | ||
|
||
Follow non-existent relative import bare to package: | ||
|
||
```py path=package5/bar.py | ||
from . import X # error: [unresolved-import] | ||
reveal_type(X) # revealed: Unknown | ||
``` | ||
|
||
Follow relative import from dunder init: | ||
|
||
````markdown | ||
```py path=package6/__init__.py | ||
from .foo import X | ||
reveal_type(X) # revealed: Literal[42] | ||
``` | ||
|
||
```py path=package6/foo.py | ||
X = 42 | ||
``` | ||
```` | ||
|
||
Follow non-existent relative import from dunder init: | ||
|
||
```py path=package7/__init__.py | ||
from .foo import X # error: [unresolved-import] | ||
reveal_type(X) # revealed: Unknown | ||
``` | ||
|
||
Follow very relative import: | ||
|
||
````markdown | ||
```py path=package8/__init__.py | ||
``` | ||
|
||
```py path=package8/foo.py | ||
X = 42 | ||
``` | ||
|
||
```py path=package8/subpackage/subsubpackage/bar.py | ||
from ...foo import X | ||
reveal_type(X) # revealed: Literal[42] | ||
``` | ||
```` | ||
|
||
Imported unbound symbol is `Unknown`: | ||
|
||
````markdown | ||
```py path=package9/__init__.py | ||
``` | ||
|
||
```py path=package9/foo.py | ||
x | ||
``` | ||
|
||
```py path=package9/bar.py | ||
from .foo import x # error: [unresolved-import] | ||
reveal_type(x) # revealed: Unknown | ||
``` | ||
```` |
This file contains 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
This file contains 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