fix: extend example of complex types
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
type Meter = float
|
||||
|
||||
extend Meter {
|
||||
op __add__(Meter) -> Meter
|
||||
op __sub__(Meter) -> Meter
|
||||
def __add__: fn(Meter) -> Meter
|
||||
def __sub__: fn(Meter) -> Meter
|
||||
}
|
||||
|
||||
type Coordinate = {
|
||||
x: Meter
|
||||
y: Meter
|
||||
type Coordinate = object
|
||||
|
||||
extend Coordinate {
|
||||
prop x: Meter
|
||||
prop y: Meter
|
||||
}
|
||||
|
||||
type Difference[T <: float] = T
|
||||
type MeterDifference = Difference[Meter]
|
||||
|
||||
type CompDiff[T <: float] = {
|
||||
prop d1: Difference[T]
|
||||
prop d2: Difference[T]
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
# type: ignore
|
||||
# ruff: disable [F821]
|
||||
|
||||
p1: Coordinate
|
||||
p2: Coordinate
|
||||
|
||||
@@ -9,6 +10,21 @@ diff_y = p2.y - p1.y
|
||||
dist = diff_x + diff_y
|
||||
|
||||
p2.x += cast(Meter, 1)
|
||||
p2.y = True
|
||||
p2.z = 3
|
||||
p2.x.a = 3
|
||||
p2.y = True # invalid, wrong type
|
||||
p2.z = 3 # invalid, no property 'z' on Coordinate
|
||||
p2.x.a = 3 # invalid, no properties on Meter
|
||||
|
||||
foo: list[float] = []
|
||||
|
||||
append = foo.append
|
||||
|
||||
foo.append("") # invalid, must be float
|
||||
foo.append(2)
|
||||
append(True) # invalid, must be float
|
||||
append(2)
|
||||
|
||||
bar: list[list[Meter]]
|
||||
|
||||
bar.append([p2.x])
|
||||
|
||||
foo2 = foo + foo
|
||||
|
||||
Reference in New Issue
Block a user