Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad74b7d

Browse files
committed
Abstract the creation of signature lines for callable things; the new
\py@sigline macro will wrap the argument list so it will not extend into the right margin. Substantially based on a contribution from Dave Cole. This addresses one of the comments in SF bug #574742.
1 parent a98011c commit ad74b7d

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

Doc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Mauro Cicognini
4040
Gilles Civario
4141
Mike Clarkson
4242
Steve Clift
43+
Dave Cole
4344
Matthew Cowles
4445
Jeremy Craven
4546
Andrew Dalke

Doc/texinputs/python.sty

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,23 @@
581581
% something else.
582582
\newcommand{\py@unspecified}{...}
583583

584+
585+
\newlength{\py@argswidth}
586+
\newcommand{\py@sigparams}[1]{%
587+
\parbox[t]{\py@argswidth}{\py@varvars{#1}\code{)}}}
588+
\newcommand{\py@sigline}[2]{%
589+
\settowidth{\py@argswidth}{#1\code{(}}%
590+
\addtolength{\py@argswidth}{-2\py@argswidth}%
591+
\addtolength{\py@argswidth}{\textwidth}%
592+
\item[#1\code{(}\py@sigparams{#2}]}
593+
584594
% C functions ------------------------------------------------------------
585595
% \begin{cfuncdesc}[refcount]{type}{name}{arglist}
586596
% Note that the [refcount] slot should only be filled in by
587597
% tools/anno-api.py; it pulls the value from the refcounts database.
588598
\newcommand{\cfuncline}[3]{
589-
\item[\code{#1 \bfcode{#2}(\py@varvars{#3})}\index{#2@{\py@idxcode{#2()}}}]
599+
\py@sigline{\code{#1 \bfcode{#2}}}{#3}%
600+
\index{#2@{\py@idxcode{#2()}}}
590601
}
591602
\newenvironment{cfuncdesc}[4][\py@badkey]{
592603
\begin{fulllineitems}
@@ -645,7 +656,8 @@
645656
}{\end{fulllineitems}}
646657

647658
% similar to {funcdesc}, but doesn't add to the index
648-
\newcommand{\funclineni}[2]{\item[\code{\bfcode{#1}(\py@varvars{#2})}]}
659+
\newcommand{\funclineni}[2]{%
660+
\py@sigline{\bfcode{#1}}{#2}}
649661
\newenvironment{funcdescni}[2]{
650662
\begin{fulllineitems}
651663
\funclineni{#1}{#2}
@@ -657,8 +669,8 @@
657669
% Using \renewcommand doesn't work for this, for unknown reasons:
658670
\global\def\py@thisclass{#1}
659671
\begin{fulllineitems}
660-
\item[\strong{class }\code{\bfcode{#1}(\py@varvars{#2})}%
661-
\index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}]
672+
\py@sigline{\strong{class }\bfcode{#1}}{#2}%
673+
\index{#1@{\py@idxcode{#1}} (class in \py@thismodule)}
662674
}{\end{fulllineitems}}
663675

664676
% \begin{classdesc*}{name}
@@ -676,8 +688,8 @@
676688
% Using \renewcommand doesn't work for this, for unknown reasons:
677689
\global\def\py@thisclass{#1}
678690
\begin{fulllineitems}
679-
\item[\strong{exception }\code{\bfcode{#1}(\py@varvars{#2})}%
680-
\index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}]
691+
\py@sigline{\strong{exception }\bfcode{#1}}{#2}%
692+
\index{#1@{\py@idxcode{#1}} (exception in \py@thismodule)}
681693
}{\end{fulllineitems}}
682694

683695
% There is no corresponding {excclassdesc*} environment. To describe
@@ -709,7 +721,7 @@
709721
% similar to {methoddesc}, but doesn't add to the index
710722
% (never actually uses the optional argument)
711723
\newcommand{\methodlineni}[3][\py@classbadkey]{%
712-
\item[\code{\bfcode{#2}(\py@varvars{#3})}]}
724+
\py@sigline{\bfcode{#2}}{#3}}
713725
\newenvironment{methoddescni}[3][\py@classbadkey]{
714726
\begin{fulllineitems}
715727
\methodlineni{#2}{#3}

0 commit comments

Comments
 (0)