Skip to content

Commit 3ece208

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5cb1da5 commit 3ece208

File tree

7 files changed

+30
-33
lines changed

7 files changed

+30
-33
lines changed

INPUTS/required/required.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict, Tuple, Union
1+
from typing import TypedDict
22
from typing_extensions import NotRequired, Required
33

44

@@ -8,19 +8,18 @@ class Movie(TypedDict, total=False):
88
year: int
99

1010

11-
m = Movie(title='The Matrix', year=1999)
11+
m = Movie(title="The Matrix", year=1999)
1212
# m = Movie()
1313
print(m)
1414

1515

1616
# --- Assignment Based TypedDict ---
17-
Movie2 = TypedDict('Movie2', {
18-
'title': Required[str],
19-
'year': int,
20-
}, total=False)
17+
class Movie2(TypedDict, total=False):
18+
title: Required[str]
19+
year: int
2120

2221

23-
m2 = Movie2(title='The Matrix Reloaded', year=2003)
22+
m2 = Movie2(title="The Matrix Reloaded", year=2003)
2423
# m2 = Movie2()
2524
print(m2)
2625

@@ -31,19 +30,19 @@ class Movie(TypedDict, total=False):
3130

3231

3332
# --- Required[] inside other Required[] (error) ---
34-
'''
33+
"""
3534
Movie3 = TypedDict('Movie3', {
3635
'title': Required[Union[
3736
Required[str],
3837
bytes
3938
]],
4039
'year': int,
4140
}, total=False)
42-
'''
41+
"""
4342

4443

4544
# --- Required[] used within TypedDict but not at top level (error) ---
46-
'''
45+
"""
4746
Movie4 = TypedDict('Movie4', {
4847
'title': Union[
4948
Required[str],
@@ -58,7 +57,7 @@ class Movie(TypedDict, total=False):
5857
],
5958
'year': int,
6059
}, total=False)
61-
'''
60+
"""
6261

6362

6463
# ==============================================================================
@@ -68,18 +67,17 @@ class MovieN(TypedDict):
6867
year: NotRequired[int]
6968

7069

71-
m = MovieN(title='The Matrix', year=1999)
70+
m = MovieN(title="The Matrix", year=1999)
7271
# m = MovieN()
7372
print(m)
7473

7574

7675
# --- Assignment Based TypedDict ---
77-
MovieN2 = TypedDict('MovieN2', {
78-
'title': str,
79-
'year': NotRequired[int],
80-
})
76+
class MovieN2(TypedDict):
77+
title: str
78+
year: NotRequired[int]
8179

8280

83-
m2 = MovieN2(title='The Matrix Reloaded', year=2003)
81+
m2 = MovieN2(title="The Matrix Reloaded", year=2003)
8482
# m2 = MovieN2()
85-
print(m2)
83+
print(m2)

INPUTS/required/required_py3_11.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import typing
22

3+
34
class Movie(typing.TypedDict):
45
title: str
56
year: typing.NotRequired[int]
67

7-
m = Movie(title='The Matrix')
8+
9+
m = Movie(title="The Matrix")
810
print(m)

INPUTS/test_typeform.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
from typing import Any, Callable, cast, Never, NoReturn, Optional, reveal_type, Type, TypeVar, TypedDict
2-
from typing_extensions import TypeForm, TypeGuard
1+
from typing_extensions import TypeForm
32

4-
dict_with_typx_keys: dict[TypeForm, int] = {
5-
int | str: 1,
6-
str | None: 2,
7-
}
3+
dict_with_typx_keys: dict[TypeForm, int] = {int | str: 1, str | None: 2}
84
dict_with_typx_keys[int | str] += 1
95

10-
#typx1: TypeForm[int | str] = 'int | str' # OK
11-
#typx2: TypeForm[int] = 'str' # E: Incompatible types in assignment (expression has type "TypeForm[str]", variable has type "TypeForm[int]")
6+
# typx1: TypeForm[int | str] = 'int | str' # OK
7+
# typx2: TypeForm[int] = 'str' # E: Incompatible types in assignment (expression has type "TypeForm[str]", variable has type "TypeForm[int]")
128

13-
'''
9+
"""
1410
from typing import Any
1511
1612
T = TypeVar('T')
@@ -35,4 +31,4 @@ def as_instance(typx: TypeForm[T]) -> T | None:
3531
reveal_type(as_type(int))
3632
reveal_type(as_instance(int | str))
3733
reveal_type(as_instance(int))
38-
'''
34+
"""

INPUTS/typeform_assign_to_alias.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
alias: TypeAlias = int | None
44
reveal_type(alias)
5-

INPUTS/typeform_assignment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
# E: Incompatible types in assignment (expression has type "UnionType", variable has type "type") [assignment]
55
typ = str | None
66

7-
#from typing_extensions import TypeExpr as TypeForm
8-
#typx: TypeForm
9-
#typx = int | None
7+
# from typing_extensions import TypeExpr as TypeForm
8+
# typx: TypeForm
9+
# typx = int | None

INPUTS/typeform_call.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
def expect_type(typ: type) -> None:
22
pass
33

4+
45
# E: Argument 1 to "expect_type" has incompatible type "UnionType"; expected "type" [arg-type]
56
expect_type(str | None)

INPUTS/typeform_return.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ def return_type() -> type:
22
# E: Incompatible return value type (got "UnionType", expected "type") [return-value]
33
return str | None
44

5+
56
return_type()

0 commit comments

Comments
 (0)