@@ -4840,6 +4840,21 @@ def state_dsl_start(self, line: str) -> None:
4840
4840
4841
4841
self .next (self .state_modulename_name , line )
4842
4842
4843
+ def update_function_kind (self , fullname : str ) -> None :
4844
+ fields = fullname .split ('.' )
4845
+ name = fields .pop ()
4846
+ _ , cls = self .clinic ._module_and_class (fields )
4847
+ if name in unsupported_special_methods :
4848
+ fail (f"{ name !r} is a special method and cannot be converted to Argument Clinic!" )
4849
+ if name == '__new__' :
4850
+ if (self .kind is not CLASS_METHOD ) or (not cls ):
4851
+ fail ("'__new__' must be a class method!" )
4852
+ self .kind = METHOD_NEW
4853
+ elif name == '__init__' :
4854
+ if (self .kind is not CALLABLE ) or (not cls ):
4855
+ fail ("'__init__' must be a normal method, not a class or static method!" )
4856
+ self .kind = METHOD_INIT
4857
+
4843
4858
def state_modulename_name (self , line : str ) -> None :
4844
4859
# looking for declaration, which establishes the leftmost column
4845
4860
# line should be
@@ -4888,6 +4903,7 @@ def state_modulename_name(self, line: str) -> None:
4888
4903
function_name = fields .pop ()
4889
4904
module , cls = self .clinic ._module_and_class (fields )
4890
4905
4906
+ self .update_function_kind (full_name )
4891
4907
overrides : dict [str , Any ] = {
4892
4908
"name" : function_name ,
4893
4909
"full_name" : full_name ,
@@ -4948,20 +4964,9 @@ def state_modulename_name(self, line: str) -> None:
4948
4964
function_name = fields .pop ()
4949
4965
module , cls = self .clinic ._module_and_class (fields )
4950
4966
4951
- fields = full_name .split ('.' )
4952
- if fields [- 1 ] in unsupported_special_methods :
4953
- fail (f"{ fields [- 1 ]} is a special method and cannot be converted to Argument Clinic! (Yet.)" )
4954
-
4955
- if fields [- 1 ] == '__new__' :
4956
- if (self .kind is not CLASS_METHOD ) or (not cls ):
4957
- fail ("__new__ must be a class method!" )
4958
- self .kind = METHOD_NEW
4959
- elif fields [- 1 ] == '__init__' :
4960
- if (self .kind is not CALLABLE ) or (not cls ):
4961
- fail ("__init__ must be a normal method, not a class or static method!" )
4962
- self .kind = METHOD_INIT
4963
- if not return_converter :
4964
- return_converter = init_return_converter ()
4967
+ self .update_function_kind (full_name )
4968
+ if self .kind is METHOD_INIT and not return_converter :
4969
+ return_converter = init_return_converter ()
4965
4970
4966
4971
if not return_converter :
4967
4972
return_converter = CReturnConverter ()
0 commit comments