@@ -4730,6 +4730,7 @@ def state_modulename_name(self, line: str | None) -> None:
4730
4730
return
4731
4731
4732
4732
line , _ , returns = line .partition ('->' )
4733
+ returns = returns .strip ()
4733
4734
4734
4735
full_name , _ , c_basename = line .partition (' as ' )
4735
4736
full_name = full_name .strip ()
@@ -4743,23 +4744,21 @@ def state_modulename_name(self, line: str | None) -> None:
4743
4744
return_converter = None
4744
4745
if returns :
4745
4746
ast_input = f"def x() -> { returns } : pass"
4746
- module = None
4747
4747
try :
4748
- module = ast .parse (ast_input )
4748
+ module_node = ast .parse (ast_input )
4749
4749
except SyntaxError :
4750
- pass
4751
- if not module :
4752
- fail ( "Badly-formed annotation for " + full_name + ": " + returns )
4750
+ fail ( f"Badly formed annotation for { full_name } : { returns !r } " )
4751
+ function_node = module_node . body [ 0 ]
4752
+ assert isinstance ( function_node , ast . FunctionDef )
4753
4753
try :
4754
- name , legacy , kwargs = self .parse_converter (module . body [ 0 ] .returns )
4754
+ name , legacy , kwargs = self .parse_converter (function_node .returns )
4755
4755
if legacy :
4756
- fail ("Legacy converter {!r} not allowed as a return converter"
4757
- .format (name ))
4756
+ fail (f"Legacy converter { name !r} not allowed as a return converter" )
4758
4757
if name not in return_converters :
4759
- fail ("No available return converter called " + repr ( name ) )
4758
+ fail (f "No available return converter called { name !r } " )
4760
4759
return_converter = return_converters [name ](** kwargs )
4761
4760
except ValueError :
4762
- fail ("Badly- formed annotation for " + full_name + ": " + returns )
4761
+ fail (f "Badly formed annotation for { full_name } : { returns !r } " )
4763
4762
4764
4763
fields = [x .strip () for x in full_name .split ('.' )]
4765
4764
function_name = fields .pop ()
0 commit comments