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