@@ -50,7 +50,9 @@ def on_event(message: Union[Foo, Bar]): ...
5050 def decorator (f : Callable [..., Any ]) -> Callable [..., Any ]:
5151 # Validate required kwargs only when decorator is used with args
5252 if pubsub is None or topic is None :
53- raise ValueError ("`pubsub` and `topic` are required when using @message_router with arguments." )
53+ raise ValueError (
54+ "`pubsub` and `topic` are required when using @message_router with arguments."
55+ )
5456
5557 sig = inspect .signature (f )
5658 if "message" not in sig .parameters :
@@ -60,7 +62,9 @@ def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
6062 try :
6163 hints = get_type_hints (f , globalns = f .__globals__ )
6264 except Exception :
63- logger .debug ("Failed to fully resolve type hints for %s" , f .__name__ , exc_info = True )
65+ logger .debug (
66+ "Failed to fully resolve type hints for %s" , f .__name__ , exc_info = True
67+ )
6468 hints = getattr (f , "__annotations__" , {}) or {}
6569
6670 raw_hint = hints .get ("message" )
@@ -72,7 +76,9 @@ def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
7276
7377 models = extract_message_models (raw_hint )
7478 if not models :
75- raise TypeError (f"Unsupported or unresolved message type for '{ f .__name__ } ': { raw_hint !r} " )
79+ raise TypeError (
80+ f"Unsupported or unresolved message type for '{ f .__name__ } ': { raw_hint !r} "
81+ )
7682
7783 # Optional early validation of supported schema kinds
7884 for m in models :
@@ -82,10 +88,11 @@ def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
8288 data = {
8389 "pubsub" : pubsub ,
8490 "topic" : topic ,
85- "dead_letter_topic" : dead_letter_topic or (f"{ topic } _DEAD" if topic else None ),
91+ "dead_letter_topic" : dead_letter_topic
92+ or (f"{ topic } _DEAD" if topic else None ),
8693 "is_broadcast" : broadcast ,
87- "message_schemas" : models , # list[type]
88- "message_types" : [m .__name__ for m in models ], # list[str]
94+ "message_schemas" : models , # list[type]
95+ "message_types" : [m .__name__ for m in models ], # list[str]
8996 }
9097
9198 # Attach metadata; deepcopy for defensive isolation
@@ -94,9 +101,13 @@ def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
94101
95102 logger .debug (
96103 "@message_router: '%s' => models %s (topic=%s, pubsub=%s, broadcast=%s)" ,
97- f .__name__ , [m .__name__ for m in models ], topic , pubsub , broadcast
104+ f .__name__ ,
105+ [m .__name__ for m in models ],
106+ topic ,
107+ pubsub ,
108+ broadcast ,
98109 )
99110 return f
100111
101112 # Support both @message_router(...) and bare @message_router usage
102- return decorator if func is None else decorator (func )
113+ return decorator if func is None else decorator (func )
0 commit comments