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] Statically known branches #15019

Merged
merged 80 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
7daaba8
[red-knot] Statically known branches
sharkdp Nov 27, 2024
2c38c42
Temporarily patch typeshed to avoid cycles
sharkdp Dec 17, 2024
fb983e7
Another patch to fix the sys.version_info tests
sharkdp Dec 17, 2024
dfc8139
Fix string annotation tests
sharkdp Dec 17, 2024
4b1681c
Reset symbol states after if-elif-else chains
sharkdp Dec 17, 2024
d4a6c4c
Add support for sys.platform
sharkdp Dec 17, 2024
a7e0fff
Add tests for common use cases
sharkdp Dec 17, 2024
47ad250
Fix match control flow
sharkdp Dec 17, 2024
665658f
Fix match control flow
sharkdp Dec 17, 2024
5c644a7
Fix boolean expression tests
sharkdp Dec 17, 2024
e24633f
Clippy suggestions
sharkdp Dec 17, 2024
a096bb2
Update snapshots
sharkdp Dec 17, 2024
cf2c32e
Fix serde feature compilation problem
sharkdp Dec 17, 2024
932da3a
Add recursion limit hack
sharkdp Dec 17, 2024
c2f2224
Short circuit, increase threshold
sharkdp Dec 17, 2024
5db776b
Renamings
sharkdp Dec 17, 2024
e234829
Introduce VisibilityConstraints struct
sharkdp Dec 18, 2024
68593f5
Minor cleanup
sharkdp Dec 18, 2024
0583120
Refactoring
sharkdp Dec 18, 2024
69b65b4
Rename
sharkdp Dec 18, 2024
af4bc96
Further cleanup
sharkdp Dec 18, 2024
ce0ff5f
Rename, comment
sharkdp Dec 18, 2024
ef0f0ba
Refactor
sharkdp Dec 18, 2024
f7a7f90
Reactivate symbol_state tests
sharkdp Dec 18, 2024
cef8cab
sys.platform documentation
sharkdp Dec 18, 2024
5a3f9bc
Clippy
sharkdp Dec 18, 2024
ad7a897
Fix fuzz build
sharkdp Dec 18, 2024
8fe6a1d
Extend sys.platform tests
sharkdp Dec 18, 2024
7f42783
Implement if-expressions
sharkdp Dec 18, 2024
1dafd1c
Fix boolean expressions
sharkdp Dec 18, 2024
dcdeade
Revert "Fix boolean expressions"
sharkdp Dec 18, 2024
984d462
Document current limitations
sharkdp Dec 18, 2024
1d39706
Rename constraints
sharkdp Dec 18, 2024
daf7d83
Rename constraints
sharkdp Dec 19, 2024
843c470
Finally!!
sharkdp Dec 19, 2024
53f5d32
Minor renamings
sharkdp Dec 19, 2024
90ecdb5
Clippy
sharkdp Dec 19, 2024
d6ae0aa
Fix doc comments
sharkdp Dec 19, 2024
900a22c
Add cross-module test to show that result is based on type inference
sharkdp Dec 19, 2024
ab03a4a
Rename
sharkdp Dec 19, 2024
cb402c5
Simplify iterators
sharkdp Dec 19, 2024
8671bf5
scope_start_visibility
sharkdp Dec 19, 2024
5162de2
Rename to simplify_visibility_constraints
sharkdp Dec 19, 2024
a3e5463
Fix comment
sharkdp Dec 19, 2024
694cabf
Update comment
sharkdp Dec 19, 2024
233d268
Handle ambiguous visibility, fix while-loop inference
sharkdp Dec 19, 2024
2e4b568
Clippy
sharkdp Dec 19, 2024
8097d41
Fix tests after rebase
sharkdp Dec 19, 2024
2da12b8
Remove _iter suffix
sharkdp Dec 19, 2024
54f56ac
Store Expression<'db> inside VisibilityConstraint
sharkdp Dec 19, 2024
e78f840
Use iterators instead of vec
sharkdp Dec 19, 2024
5dcd7ca
Short circuit if declared type is available
sharkdp Dec 19, 2024
9e1425f
Always build a union of inferred_ty and declared_ty
sharkdp Dec 19, 2024
0e430b6
Raise diagnostic for possibly-undeclared symbols
sharkdp Dec 19, 2024
9092aad
Add section for yet-unsupported features
sharkdp Dec 19, 2024
564ea98
Simplify code in simplify_visibility_constraints
sharkdp Dec 19, 2024
ad3b81e
Use actual return values in dummy functions
sharkdp Dec 20, 2024
52129a6
Use struct instead of three-tuple
sharkdp Dec 20, 2024
7c55b67
::default() instead of ::new()
sharkdp Dec 20, 2024
2a0672a
Minor review comments
sharkdp Dec 20, 2024
4ce2d2a
Use KnownModule
sharkdp Dec 20, 2024
d3216fe
Minor iterator changes
sharkdp Dec 20, 2024
f0b7f47
More minor changes
sharkdp Dec 20, 2024
db0e190
Revert possibly-unbound changes
sharkdp Dec 20, 2024
a84614c
Documentation
sharkdp Dec 20, 2024
40525db
Separate struct for declaration ids with constraint
sharkdp Dec 20, 2024
a448b3a
More documentation
sharkdp Dec 20, 2024
96d8faa
Adapt use-def documentation
sharkdp Dec 20, 2024
2dc3276
Add section on static visibility
sharkdp Dec 20, 2024
87b5da8
Add module-level documentation
sharkdp Dec 20, 2024
bf0002e
Set recursion limit to 24, document the limitation
sharkdp Dec 20, 2024
b133549
Make `symbol_by_id` a salsa query
MichaReiser Dec 20, 2024
4f4c142
Add section regarding ambiguity
sharkdp Dec 20, 2024
c158577
fmt skip
sharkdp Dec 21, 2024
4ee8fe4
Truthy/Falsy instead of Literal[True/False]
sharkdp Dec 21, 2024
feb9f1b
Only first entry should be None
sharkdp Dec 21, 2024
dcd00c5
Fix visibility
sharkdp Dec 21, 2024
9d57adf
Remove visibility_constraints reference from iterator
sharkdp Dec 21, 2024
b455093
Add comment regarding performance
sharkdp Dec 21, 2024
95d079c
txt-sections to prevent doctest failures
sharkdp Dec 21, 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