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