File tree Expand file tree Collapse file tree 2 files changed +21
-15
lines changed Expand file tree Collapse file tree 2 files changed +21
-15
lines changed Original file line number Diff line number Diff line change 6
6
7
7
8
8
def make_object (cls ):
9
- return cls ()
9
+ ...
10
10
11
11
12
12
## End of your code ##
13
+ from typing import assert_type
14
+
15
+
13
16
class MyClass :
14
17
pass
15
18
@@ -18,8 +21,9 @@ def f():
18
21
pass
19
22
20
23
21
- c = make_object (MyClass )
22
- c = make_object (int )
23
- c = make_object (f ) # expect-type-error
24
- c = make_object ("sss" ) # expect-type-error
25
- c = make_object (["sss" ]) # expect-type-error
24
+ assert_type (make_object (MyClass ), MyClass )
25
+ assert_type (make_object (int ), int )
26
+
27
+ make_object (f ) # expect-type-error
28
+ make_object ("sss" ) # expect-type-error
29
+ make_object (["sss" ]) # expect-type-error
Original file line number Diff line number Diff line change 4
4
`make_object` takes a class returns an instance of it.
5
5
"""
6
6
7
- from typing import Any
8
7
9
-
10
- def make_object (cls : type [Any ]):
11
- return cls ()
8
+ def make_object [T ](cls : type [T ]) -> T :
9
+ ...
12
10
13
11
14
12
## End of your code ##
13
+ from typing import assert_type
14
+
15
+
15
16
class MyClass :
16
17
pass
17
18
@@ -20,8 +21,9 @@ def f():
20
21
pass
21
22
22
23
23
- c = make_object (MyClass )
24
- c = make_object (int )
25
- c = make_object (f ) # expect-type-error
26
- c = make_object ("sss" ) # expect-type-error
27
- c = make_object (["sss" ]) # expect-type-error
24
+ assert_type (make_object (MyClass ), MyClass )
25
+ assert_type (make_object (int ), int )
26
+
27
+ make_object (f ) # expect-type-error
28
+ make_object ("sss" ) # expect-type-error
29
+ make_object (["sss" ]) # expect-type-error
You can’t perform that action at this time.
0 commit comments