@@ -5016,22 +5016,26 @@ def bad_node(self, node):
5016
5016
key = f"{ parameter_name } _as_{ c_name } " if c_name else parameter_name
5017
5017
self .function .parameters [key ] = p
5018
5018
5019
- def parse_converter (self , annotation ):
5020
- if (isinstance (annotation , ast .Constant ) and
5021
- type (annotation .value ) is str ):
5022
- return annotation .value , True , {}
5019
+ KwargDict = dict [str | None , Any ]
5023
5020
5024
- if isinstance (annotation , ast .Name ):
5025
- return annotation .id , False , {}
5026
-
5027
- if not isinstance (annotation , ast .Call ):
5028
- fail ("Annotations must be either a name, a function call, or a string." )
5029
-
5030
- name = annotation .func .id
5031
- symbols = globals ()
5032
-
5033
- kwargs = {node .arg : eval_ast_expr (node .value , symbols ) for node in annotation .keywords }
5034
- return name , False , kwargs
5021
+ @staticmethod
5022
+ def parse_converter (annotation : ast .expr | None ) -> tuple [str , bool , KwargDict ]:
5023
+ match annotation :
5024
+ case ast .Constant (value = str () as value ):
5025
+ return value , True , {}
5026
+ case ast .Name (name ):
5027
+ return name , False , {}
5028
+ case ast .Call (func = ast .Name (name )):
5029
+ symbols = globals ()
5030
+ kwargs = {
5031
+ node .arg : eval_ast_expr (node .value , symbols )
5032
+ for node in annotation .keywords
5033
+ }
5034
+ return name , False , kwargs
5035
+ case _:
5036
+ fail (
5037
+ "Annotations must be either a name, a function call, or a string."
5038
+ )
5035
5039
5036
5040
def parse_special_symbol (self , symbol ):
5037
5041
if symbol == '*' :
0 commit comments