Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Interned visibility constraints #15079

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e8cfb34
[red-knot] Statically known branches
sharkdp Nov 27, 2024
34be5b6
Temporarily patch typeshed to avoid cycles
sharkdp Dec 17, 2024
7b79a56
Another patch to fix the sys.version_info tests
sharkdp Dec 17, 2024
2042c68
Fix string annotation tests
sharkdp Dec 17, 2024
76e277b
Reset symbol states after if-elif-else chains
sharkdp Dec 17, 2024
3d85c7d
Add support for sys.platform
sharkdp Dec 17, 2024
dc9fbaa
Add tests for common use cases
sharkdp Dec 17, 2024
c28bcdb
Fix match control flow
sharkdp Dec 17, 2024
2b12c49
Fix match control flow
sharkdp Dec 17, 2024
e871ea1
Fix boolean expression tests
sharkdp Dec 17, 2024
00e698b
Clippy suggestions
sharkdp Dec 17, 2024
27b64a0
Update snapshots
sharkdp Dec 17, 2024
a37dac1
Fix serde feature compilation problem
sharkdp Dec 17, 2024
e044fde
Add recursion limit hack
sharkdp Dec 17, 2024
90e639b
Short circuit, increase threshold
sharkdp Dec 17, 2024
3a1dbc1
Renamings
sharkdp Dec 17, 2024
4f6fba2
Introduce VisibilityConstraints struct
sharkdp Dec 18, 2024
5df51f2
Minor cleanup
sharkdp Dec 18, 2024
79b582c
Refactoring
sharkdp Dec 18, 2024
afe1572
Rename
sharkdp Dec 18, 2024
853e171
Further cleanup
sharkdp Dec 18, 2024
2e6f757
Rename, comment
sharkdp Dec 18, 2024
8a93a9a
Refactor
sharkdp Dec 18, 2024
12f139d
Reactivate symbol_state tests
sharkdp Dec 18, 2024
9a1d1ea
sys.platform documentation
sharkdp Dec 18, 2024
81bfc52
Clippy
sharkdp Dec 18, 2024
189f2ef
Fix fuzz build
sharkdp Dec 18, 2024
c1748f0
Extend sys.platform tests
sharkdp Dec 18, 2024
d249801
Implement if-expressions
sharkdp Dec 18, 2024
8b60946
Fix boolean expressions
sharkdp Dec 18, 2024
55330c4
Revert "Fix boolean expressions"
sharkdp Dec 18, 2024
45d544b
Document current limitations
sharkdp Dec 18, 2024
6c64ae0
Rename constraints
sharkdp Dec 18, 2024
2bbd586
Rename constraints
sharkdp Dec 19, 2024
c5e32d9
Finally!!
sharkdp Dec 19, 2024
2beabc6
Minor renamings
sharkdp Dec 19, 2024
0c6c0ee
Clippy
sharkdp Dec 19, 2024
32390f3
Fix doc comments
sharkdp Dec 19, 2024
8dd5cc5
Add cross-module test to show that result is based on type inference
sharkdp Dec 19, 2024
c3d3437
Rename
sharkdp Dec 19, 2024
167337b
Simplify iterators
sharkdp Dec 19, 2024
91fa462
scope_start_visibility
sharkdp Dec 19, 2024
b37f095
Rename to simplify_visibility_constraints
sharkdp Dec 19, 2024
090563e
Fix comment
sharkdp Dec 19, 2024
47bb571
Update comment
sharkdp Dec 19, 2024
c9eb782
Handle ambiguous visibility, fix while-loop inference
sharkdp Dec 19, 2024
22e345a
Clippy
sharkdp Dec 19, 2024
a4d805f
Fix tests after rebase
sharkdp Dec 19, 2024
f9f4615
Remove _iter suffix
sharkdp Dec 19, 2024
4353730
Store Expression<'db> inside VisibilityConstraint
sharkdp Dec 19, 2024
402f279
Use iterators instead of vec
sharkdp Dec 19, 2024
c0e7c08
Short circuit if declared type is available
sharkdp Dec 19, 2024
89fefe0
Always build a union of inferred_ty and declared_ty
sharkdp Dec 19, 2024
0b70c1c
Raise diagnostic for possibly-undeclared symbols
sharkdp Dec 19, 2024
2c104c6
Add section for yet-unsupported features
sharkdp Dec 19, 2024
025804e
Simplify code in simplify_visibility_constraints
sharkdp Dec 19, 2024
2dfe682
Use actual return values in dummy functions
sharkdp Dec 20, 2024
3dde382
Use struct instead of three-tuple
sharkdp Dec 20, 2024
df35369
::default() instead of ::new()
sharkdp Dec 20, 2024
0381885
Minor review comments
sharkdp Dec 20, 2024
0d6425a
Use KnownModule
sharkdp Dec 20, 2024
b85a56d
Minor iterator changes
sharkdp Dec 20, 2024
f0e9cce
More minor changes
sharkdp Dec 20, 2024
fafecc9
Revert possibly-unbound changes
sharkdp Dec 20, 2024
b0986de
Interned visibility constraints
sharkdp Dec 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def f():

## `typing.Never`

`typing.Never` is only available in Python 3.11 and later:
`typing.Never` is only available in Python 3.11 and later.

### Python 3.11

```toml
[environment]
Expand All @@ -57,8 +59,17 @@ python-version = "3.11"
```py
from typing import Never

x: Never
reveal_type(Never) # revealed: typing.Never
```

def f():
reveal_type(x) # revealed: Never
### Python 3.10

```toml
[environment]
python-version = "3.10"
```

```py
# error: [unresolved-import]
from typing import Never
```
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ b: tuple[int] = (42,)
c: tuple[str, int] = ("42", 42)
d: tuple[tuple[str, str], tuple[int, int]] = (("foo", "foo"), (42, 42))
e: tuple[str, ...] = ()
# TODO: we should not emit this error
# error: [call-possibly-unbound-method] "Method `__class_getitem__` of type `Literal[tuple]` is possibly unbound"
f: tuple[str, *tuple[int, ...], bytes] = ("42", b"42")
g: tuple[str, Unpack[tuple[int, ...]], bytes] = ("42", b"42")
h: tuple[list[int], list[int]] = ([], [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ def _(flag: bool):

```py
if True or (x := 1):
# TODO: infer that the second arm is never executed, and raise `unresolved-reference`.
# error: [possibly-unresolved-reference]
reveal_type(x) # revealed: Literal[1]
# error: [unresolved-reference]
reveal_type(x) # revealed: Unknown

if True and (x := 1):
# TODO: infer that the second arm is always executed, do not raise a diagnostic
# error: [possibly-unresolved-reference]
reveal_type(x) # revealed: Literal[1]
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ def _(flag: bool):
def __call__(self) -> int: ...

a = NonCallable()
# error: "Object of type `Literal[__call__] | Literal[1]` is not callable (due to union element `Literal[1]`)"
reveal_type(a()) # revealed: int | Unknown
# error: "Object of type `Literal[1] | Literal[__call__]` is not callable (due to union element `Literal[1]`)"
reveal_type(a()) # revealed: Unknown | int
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def _(flag: bool):
reveal_type(1 if flag else 2) # revealed: Literal[1, 2]
```

## Statically known branches
## Statically known conditions in if-expressions

```py
reveal_type(1 if True else 2) # revealed: Literal[1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# Ellipsis literals

## Simple
## Python 3.9

```toml
[environment]
python-version = "3.9"
```

```py
reveal_type(...) # revealed: ellipsis
```

## Python 3.10

```toml
[environment]
python-version = "3.10"
```

```py
reveal_type(...) # revealed: EllipsisType | ellipsis
reveal_type(...) # revealed: EllipsisType
```
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ def _(t: type[object]):

### Handling of `None`

`types.NoneType` is only available in Python 3.10 and later:

```toml
[environment]
python-version = "3.10"
```

```py
# TODO: this error should ideally go away once we (1) understand `sys.version_info` branches,
# and (2) set the target Python version for this test to 3.10.
# error: [possibly-unbound-import] "Member `NoneType` of module `types` is possibly unbound"
from types import NoneType

def _(flag: bool):
Expand Down
Loading
Loading