File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -39,10 +39,12 @@ def get_injection_requests(
39
39
40
40
# If the type is not actually a type, give a meaningful error
41
41
if not isinstance (inject_type , type ):
42
- raise TypeError (
43
- f"Component { cname } has a non-type annotation { n } : { inject_type } \n "
44
- "Lone non-injection variable annotations are disallowed, did you want to assign a static variable?"
42
+ message = (
43
+ f"Component { cname } has a non-type annotation { n } : { inject_type !r} "
45
44
)
45
+ if component is not None :
46
+ message += "\n Lone non-injection variable annotations are disallowed. Did you mean to assign a static variable?"
47
+ raise TypeError (message )
46
48
47
49
requests [n ] = inject_type
48
50
Original file line number Diff line number Diff line change
1
+ import typing
2
+
3
+ import pytest
4
+
5
+ from magicbot .inject import get_injection_requests
6
+
7
+
8
+ def test_ctor_invalid_type_hint_message ():
9
+ """
10
+ class Component:
11
+ def __init__(self, foo: 1): ...
12
+ """
13
+ type_hints = {
14
+ "foo" : typing .cast (type , 1 ),
15
+ }
16
+
17
+ with pytest .raises (TypeError ) as exc_info :
18
+ get_injection_requests (type_hints , "bar" )
19
+
20
+ assert exc_info .value .args [0 ] == "Component bar has a non-type annotation foo: 1"
You can’t perform that action at this time.
0 commit comments