Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
edf9350a
Commit
edf9350a
authored
Apr 30, 2019
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support positional-only arguments in doc-embedded signatures.
parent
d22678c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
Cython/Compiler/AutoDocTransforms.py
Cython/Compiler/AutoDocTransforms.py
+10
-7
tests/run/embedsignatures.pyx
tests/run/embedsignatures.pyx
+6
-0
No files found.
Cython/Compiler/AutoDocTransforms.py
View file @
edf9350a
...
@@ -55,7 +55,7 @@ class EmbedSignature(CythonTransform):
...
@@ -55,7 +55,7 @@ class EmbedSignature(CythonTransform):
return
arg_doc
return
arg_doc
def
_fmt_arglist
(
self
,
args
,
def
_fmt_arglist
(
self
,
args
,
npargs
=
0
,
pargs
=
None
,
np
oargs
=
0
,
np
args
=
0
,
pargs
=
None
,
nkargs
=
0
,
kargs
=
None
,
nkargs
=
0
,
kargs
=
None
,
hide_self
=
False
):
hide_self
=
False
):
arglist
=
[]
arglist
=
[]
...
@@ -65,9 +65,11 @@ class EmbedSignature(CythonTransform):
...
@@ -65,9 +65,11 @@ class EmbedSignature(CythonTransform):
arglist
.
append
(
arg_doc
)
arglist
.
append
(
arg_doc
)
if
pargs
:
if
pargs
:
arg_doc
=
self
.
_fmt_star_arg
(
pargs
)
arg_doc
=
self
.
_fmt_star_arg
(
pargs
)
arglist
.
insert
(
npargs
,
'*%s'
%
arg_doc
)
arglist
.
insert
(
npargs
+
npoargs
,
'*%s'
%
arg_doc
)
elif
nkargs
:
elif
nkargs
:
arglist
.
insert
(
npargs
,
'*'
)
arglist
.
insert
(
npargs
+
npoargs
,
'*'
)
if
npoargs
:
arglist
.
insert
(
npoargs
,
'/'
)
if
kargs
:
if
kargs
:
arg_doc
=
self
.
_fmt_star_arg
(
kargs
)
arg_doc
=
self
.
_fmt_star_arg
(
kargs
)
arglist
.
append
(
'**%s'
%
arg_doc
)
arglist
.
append
(
'**%s'
%
arg_doc
)
...
@@ -80,12 +82,12 @@ class EmbedSignature(CythonTransform):
...
@@ -80,12 +82,12 @@ class EmbedSignature(CythonTransform):
return
ret
.
declaration_code
(
""
,
for_display
=
1
)
return
ret
.
declaration_code
(
""
,
for_display
=
1
)
def
_fmt_signature
(
self
,
cls_name
,
func_name
,
args
,
def
_fmt_signature
(
self
,
cls_name
,
func_name
,
args
,
npargs
=
0
,
pargs
=
None
,
np
oargs
=
0
,
np
args
=
0
,
pargs
=
None
,
nkargs
=
0
,
kargs
=
None
,
nkargs
=
0
,
kargs
=
None
,
return_expr
=
None
,
return_expr
=
None
,
return_type
=
None
,
hide_self
=
False
):
return_type
=
None
,
hide_self
=
False
):
arglist
=
self
.
_fmt_arglist
(
args
,
arglist
=
self
.
_fmt_arglist
(
args
,
npargs
,
pargs
,
np
oargs
,
np
args
,
pargs
,
nkargs
,
kargs
,
nkargs
,
kargs
,
hide_self
=
hide_self
)
hide_self
=
hide_self
)
arglist_doc
=
', '
.
join
(
arglist
)
arglist_doc
=
', '
.
join
(
arglist
)
...
@@ -147,11 +149,12 @@ class EmbedSignature(CythonTransform):
...
@@ -147,11 +149,12 @@ class EmbedSignature(CythonTransform):
else
:
else
:
class_name
,
func_name
=
self
.
class_name
,
node
.
name
class_name
,
func_name
=
self
.
class_name
,
node
.
name
npoargs
=
getattr
(
node
,
'num_posonly_args'
,
0
)
nkargs
=
getattr
(
node
,
'num_kwonly_args'
,
0
)
nkargs
=
getattr
(
node
,
'num_kwonly_args'
,
0
)
npargs
=
len
(
node
.
args
)
-
nkargs
npargs
=
len
(
node
.
args
)
-
nkargs
-
npoargs
signature
=
self
.
_fmt_signature
(
signature
=
self
.
_fmt_signature
(
class_name
,
func_name
,
node
.
args
,
class_name
,
func_name
,
node
.
args
,
npargs
,
node
.
star_arg
,
np
oargs
,
np
args
,
node
.
star_arg
,
nkargs
,
node
.
starstar_arg
,
nkargs
,
node
.
starstar_arg
,
return_expr
=
node
.
return_type_annotation
,
return_expr
=
node
.
return_type_annotation
,
return_type
=
None
,
hide_self
=
hide_self
)
return_type
=
None
,
hide_self
=
hide_self
)
...
...
tests/run/embedsignatures.pyx
View file @
edf9350a
...
@@ -83,6 +83,9 @@ __doc__ = ur"""
...
@@ -83,6 +83,9 @@ __doc__ = ur"""
>>> print (Ext.n.__doc__)
>>> print (Ext.n.__doc__)
Ext.n(self, a: int, b: float = 1.0, *args: tuple, **kwargs: dict) -> (None, True)
Ext.n(self, a: int, b: float = 1.0, *args: tuple, **kwargs: dict) -> (None, True)
>>> print (Ext.o.__doc__)
Ext.o(self, a, b=1, /, c=5, *args, **kwargs)
>>> print (Ext.get_int.__doc__)
>>> print (Ext.get_int.__doc__)
Ext.get_int(self) -> int
Ext.get_int(self) -> int
...
@@ -265,6 +268,9 @@ cdef class Ext:
...
@@ -265,6 +268,9 @@ cdef class Ext:
def
n
(
self
,
a
:
int
,
b
:
float
=
1.0
,
*
args
:
tuple
,
**
kwargs
:
dict
)
->
(
None
,
True
):
def
n
(
self
,
a
:
int
,
b
:
float
=
1.0
,
*
args
:
tuple
,
**
kwargs
:
dict
)
->
(
None
,
True
):
pass
pass
def
o
(
self
,
a
,
b
=
1
,
/
,
c
=
5
,
*
args
,
**
kwargs
):
pass
cpdef
int
get_int
(
self
):
cpdef
int
get_int
(
self
):
return
0
return
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment