@@ -2665,6 +2665,7 @@ class Function:
26652665 # functions with optional groups because we can't represent
26662666 # those accurately with inspect.Signature in 3.4.
26672667 docstring_only : bool = False
2668+ forced_text_signature : str | None = None
26682669
26692670 def __post_init__ (self ) -> None :
26702671 self .parent = self .cls or self .module
@@ -2724,12 +2725,12 @@ def copy(self, **overrides: Any) -> Function:
27242725 }
27252726 return f
27262727
2727- def format_docstring_signature (self , * , forced_text_signature : str | None ) -> str :
2728+ def format_docstring_signature (self ) -> str :
27282729 parameters = self .render_parameters
27292730 text , add , output = _text_accumulator ()
27302731 add (self .displayname )
2731- if forced_text_signature :
2732- add (forced_text_signature )
2732+ if self . forced_text_signature :
2733+ add (self . forced_text_signature )
27332734 else :
27342735 add ('(' )
27352736
@@ -2898,7 +2899,7 @@ def format_docstring_parameters(self) -> str:
28982899 add ('\n ' )
28992900 return output ()
29002901
2901- def format_docstring (self , * , forced_text_signature : str | None ) -> None :
2902+ def format_docstring (self ) -> None :
29022903 if self .kind .new_or_init and not self .docstring :
29032904 # don't render a docstring at all, no signature, nothing.
29042905 return
@@ -2938,9 +2939,7 @@ def format_docstring(self, *, forced_text_signature: str | None) -> None:
29382939
29392940 # finalize docstring
29402941 parameters = self .format_docstring_parameters ()
2941- signature = self .format_docstring_signature (
2942- forced_text_signature = forced_text_signature
2943- )
2942+ signature = self .format_docstring_signature ()
29442943 docstring = "\n " .join (lines )
29452944 self .docstring = linear_format (docstring ,
29462945 signature = signature ,
@@ -4803,7 +4802,6 @@ class DSLParser:
48034802 indent : IndentStack
48044803 kind : FunctionKind
48054804 coexist : bool
4806- forced_text_signature : str | None
48074805 parameter_continuation : str
48084806 preserve_output : bool
48094807 star_from_version_re = create_regex (
@@ -4840,7 +4838,6 @@ def reset(self) -> None:
48404838 self .indent = IndentStack ()
48414839 self .kind = CALLABLE
48424840 self .coexist = False
4843- self .forced_text_signature = None
48444841 self .parameter_continuation = ''
48454842 self .preserve_output = False
48464843
@@ -4982,9 +4979,10 @@ def at_coexist(self) -> None:
49824979 self .coexist = True
49834980
49844981 def at_text_signature (self , text_signature : str ) -> None :
4985- if self .forced_text_signature :
4982+ assert self .function
4983+ if self .function .forced_text_signature :
49864984 fail ("Called @text_signature twice!" )
4987- self .forced_text_signature = text_signature
4985+ self .function . forced_text_signature = text_signature
49884986
49894987 def parse (self , block : Block ) -> None :
49904988 self .reset ()
@@ -5778,7 +5776,7 @@ def check_remaining(
57785776 if self .deprecated_positional :
57795777 check_remaining ("* [from ...]" , lambda p : not p .deprecated_positional )
57805778
5781- self .function .format_docstring (forced_text_signature = self . forced_text_signature )
5779+ self .function .format_docstring ()
57825780
57835781
57845782# maps strings to callables.
0 commit comments