Skip to content

Commit a6e76bc

Browse files
committed
Formatting
1 parent f09ad13 commit a6e76bc

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

crates/red_knot_python_semantic/resources/mdtest/narrow/type_guards.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def _(
2222

2323
def f(a) -> TypeGuard[str]: ...
2424
def g(a) -> TypeIs[str]: ...
25-
2625
def _(a: object):
2726
reveal_type(f(a)) # revealed: TypeGuard[a, str]
2827
reveal_type(g(a)) # revealed: TypeIs[a, str]
@@ -43,12 +42,14 @@ def _() -> TypeGuard[str]: ...
4342
def _(**kwargs) -> TypeIs[str]: ...
4443

4544
class _:
45+
# fine
4646
def _(self, /, a) -> TypeGuard[str]: ...
4747
@classmethod
4848
def _(cls, a) -> TypeGuard[str]: ...
4949
@staticmethod
5050
def _(a) -> TypeIs[str]: ...
5151

52+
# errors
5253
def _(self) -> TypeGuard[str]: ... # error: [invalid-type-guard-definition]
5354
def _(self, /, *, a) -> TypeGuard[str]: ... # error: [invalid-type-guard-definition]
5455
@classmethod
@@ -74,6 +75,7 @@ def _(a) -> TypeIs[str]: ...
7475

7576
# error: [invalid-type-guard-definition]
7677
def _(a: int) -> TypeIs[str]: ...
78+
7779
# error: [invalid-type-guard-definition]
7880
def _(a: bool | str) -> TypeIs[int]: ...
7981
```
@@ -89,6 +91,7 @@ a = 123
8991

9092
# error: [invalid-type-form]
9193
def f(_) -> TypeGuard[int, str]: ...
94+
9295
# error: [invalid-type-form]
9396
def g(_) -> TypeIs[a, str]: ...
9497

@@ -109,14 +112,14 @@ def f(a: object, flag: bool) -> TypeGuard[str]:
109112
return 1
110113

111114
# TODO: Emit a diagnostic
112-
return ''
115+
return ""
113116

114-
def g(a: Literal['foo', 'bar']) -> TypeIs[Literal['foo']]:
117+
def g(a: Literal["foo", "bar"]) -> TypeIs[Literal["foo"]]:
115118
match a:
116-
case 'foo':
119+
case "foo":
117120
# Logically wrong, but allowed regardless
118121
return False
119-
case 'bar':
122+
case "bar":
120123
return False
121124
case _:
122125
assert_never(a)
@@ -130,10 +133,9 @@ from typing_extensions import TypeGuard, TypeIs
130133

131134
def f(a: object) -> TypeGuard[str]: ...
132135
def g(a: object) -> TypeIs[int]: ...
133-
134136
def _(d: Any):
135137
if f(): # error: [missing-argument]
136-
...
138+
...
137139

138140
# TODO: Is this error correct?
139141
if g(*d): # error: [missing-argument]
@@ -143,7 +145,7 @@ def _(d: Any):
143145
...
144146

145147
if g(a=d): # error: [invalid-type-guard-call]
146-
...
148+
...
147149

148150
def _(a: tuple[str, int] | tuple[int, str]):
149151
if g(a[0]): # error: [invalid-type-guard-call]
@@ -159,7 +161,6 @@ from typing_extensions import TypeGuard, TypeIs
159161

160162
def guard_str(a: object) -> TypeGuard[str]: ...
161163
def is_int(a: object) -> TypeIs[int]: ...
162-
163164
def _(a: str | int):
164165
if guard_str(a):
165166
reveal_type(a) # revealed: str
@@ -194,7 +195,7 @@ def _(x: str | int, flag: bool) -> None:
194195
reveal_type(b) # revealed: TypeIs[x, int]
195196

196197
if flag:
197-
x = ''
198+
x = ""
198199

199200
if b:
200201
reveal_type(x) # revealed: str | int
@@ -208,7 +209,6 @@ from typing_extensions import TypeGuard
208209

209210
def guard_int(a: object) -> TypeGuard[int]: ...
210211
def is_int(a: object) -> TypeGuard[int]: ...
211-
212212
def does_not_narrow_in_negative_case(a: str | int):
213213
if not guard_int(a):
214214
reveal_type(a) # revealed: str | int

crates/red_knot_python_semantic/src/types/diagnostic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ pub(crate) fn report_type_guard_function_with_incorrect_arity(
12001200
"This type guard function must accept at least {} positional arguments",
12011201
if is_non_static_method { 2 } else { 1 }
12021202
),
1203-
)
1203+
);
12041204
}
12051205

12061206
pub(crate) fn report_typeis_function_with_incorrect_types<'db>(
@@ -1218,5 +1218,5 @@ pub(crate) fn report_typeis_function_with_incorrect_types<'db>(
12181218
return_ty.display(db),
12191219
input_ty.display(db),
12201220
),
1221-
)
1221+
);
12221222
}

0 commit comments

Comments
 (0)