Commit edf9350a authored by Stefan Behnel's avatar Stefan Behnel

Support positional-only arguments in doc-embedded signatures.

parent d22678c7
...@@ -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, npoargs=0, npargs=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, npoargs=0, npargs=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, npoargs, npargs, 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, npoargs, npargs, 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)
......
...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment