@@ -4840,6 +4840,21 @@ def state_dsl_start(self, line: str) -> None:
48404840
48414841 self .next (self .state_modulename_name , line )
48424842
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+
48434858 def state_modulename_name (self , line : str ) -> None :
48444859 # looking for declaration, which establishes the leftmost column
48454860 # line should be
@@ -4888,6 +4903,7 @@ def state_modulename_name(self, line: str) -> None:
48884903 function_name = fields .pop ()
48894904 module , cls = self .clinic ._module_and_class (fields )
48904905
4906+ self .update_function_kind (full_name )
48914907 overrides : dict [str , Any ] = {
48924908 "name" : function_name ,
48934909 "full_name" : full_name ,
@@ -4948,20 +4964,9 @@ def state_modulename_name(self, line: str) -> None:
49484964 function_name = fields .pop ()
49494965 module , cls = self .clinic ._module_and_class (fields )
49504966
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 ()
49654970
49664971 if not return_converter :
49674972 return_converter = CReturnConverter ()
0 commit comments