@@ -123,13 +123,15 @@ def wrap(self, func: Callable, switcher: "Switcher") -> Callable:
123123 type_checks = self ._compile_type_checks (typerule , param_names )
124124
125125 # Register the rule
126- self ._type_rules .append ({
127- "func" : func ,
128- "typerule" : typerule ,
129- "signature" : sig ,
130- "param_names" : param_names ,
131- "type_checks" : type_checks ,
132- })
126+ self ._type_rules .append (
127+ {
128+ "func" : func ,
129+ "typerule" : typerule ,
130+ "signature" : sig ,
131+ "param_names" : param_names ,
132+ "type_checks" : type_checks ,
133+ }
134+ )
133135
134136 return func
135137
@@ -141,20 +143,24 @@ def _inject_dispatch(self, switcher: "Switcher"):
141143 def enhanced_call (arg = None , / , * , typerule = None , valrule = None ):
142144 # If typerule specified, attach metadata to function for later registration
143145 if typerule is not None :
146+
144147 def decorator (func ):
145148 func ._smartswitch_typerule = typerule
146149 return original_call (func )
150+
147151 return decorator
148152
149153 # Dispatch mode: switch()(*args, **kwargs)
150154 if arg is None and typerule is None and valrule is None :
155+
151156 def invoker (* args , ** kwargs ):
152157 # Try type rules
153158 for rule in self ._type_rules :
154159 if self ._matches_typerule (rule , args , kwargs ):
155160 return rule ["func" ](* args , ** kwargs )
156161 # Fall back to original dispatch
157162 raise ValueError (f"No type rule matched for { args } , { kwargs } " )
163+
158164 return invoker
159165
160166 # Otherwise use original behavior
0 commit comments