Skip to content

Commit ad83ea5

Browse files
committed
Add test for redeclaration with a more static type
1 parent 1e24cdd commit ad83ea5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/red_knot_python_semantic/resources/mdtest/attributes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,23 @@ def _(flag: bool, flag1: bool, flag2: bool):
816816
reveal_type(C().x) # revealed: Unknown | Literal[1, 2, 3]
817817
```
818818

819+
### Possibly-unbound within gradual types
820+
821+
```py
822+
from typing import Any
823+
824+
def _(flag: bool):
825+
class Base:
826+
x: Any
827+
828+
class Derived(Base):
829+
if flag:
830+
# Redeclaring `x` with a more static type is okay in terms of LSP.
831+
x: int
832+
833+
reveal_type(Derived().x) # revealed: int | Any
834+
```
835+
819836
### Attribute possibly unbound on a subclass but not on a superclass
820837

821838
```py

0 commit comments

Comments
 (0)