Skip to content

Commit

Permalink
Scoped rendering of py:function
Browse files Browse the repository at this point in the history
Also, switches from deprecated PyModulelevel to PyFunction.
Also, fixes issue with false typing of function arguments.
  • Loading branch information
jakobandersen committed May 1, 2020
1 parent 1982589 commit 5a15303
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class CMacroObject(BaseObject, c.CMacroObject):
pass


# ----------------------------------------------------------------------------

class PyFunction(BaseObject, python.PyFunction):
pass


# ----------------------------------------------------------------------------

class DomainDirectiveFactory(object):
Expand Down Expand Up @@ -144,8 +150,10 @@ class DomainDirectiveFactory(object):
'typedef': (CTypeObject, 'type'),
}
python_classes = {
'function': (python.PyModulelevel, 'function'),
'variable': (python.PyClassmember, 'attribute')
'function': (PyFunction, 'function'),
'variable': (python.PyClassmember, 'attribute'),
'class': (python.PyClasslike, 'class'),
'namespace': (python.PyClasslike, 'class'),
}

if php is not None:
Expand All @@ -157,14 +165,6 @@ class DomainDirectiveFactory(object):
'global': (php.PhpGloballevel, 'global'),
}

@staticmethod
def fix_python_signature(sig):
def_ = 'def '
if sig.startswith(def_):
sig = sig[len(def_):]
# Doxygen uses an invalid separator ('::') in Python signatures. Replace them with '.'.
return sig.replace('::', '.')

@staticmethod
def create(domain, args):
if domain == 'c':
Expand All @@ -174,9 +174,8 @@ def create(domain, args):
cls, name = DomainDirectiveFactory.c_classes[args[0]]
args[1] = [n.replace('::', '.') for n in args[1]]
elif domain == 'py':
cls, name = DomainDirectiveFactory.python_classes.get(
args[0], (python.PyClasslike, 'class'))
args[1] = [DomainDirectiveFactory.fix_python_signature(n) for n in args[1]]
cls, name = DomainDirectiveFactory.python_classes[args[0]]
args[1] = [n.replace('::', '.') for n in args[1]]
elif php is not None and domain == 'php':
separators = php.separators
arg_0 = args[0]
Expand Down Expand Up @@ -1340,15 +1339,19 @@ def visit_linkedtext(self, node):

def visit_function(self, node):
dom = self.get_domain()
if not dom or dom in ('c', 'cpp'):
if not dom or dom in ('c', 'cpp', 'py'):
names = self.get_qualification()
names.append(node.get_name())
declaration = ' '.join([
self.create_template_prefix(node),
''.join(n.astext() for n in self.render(node.get_type())),
self.join_nested_name(names),
node.get_argsstring()
])
name = self.join_nested_name(names)
if dom == 'py':
declaration = name + node.get_argsstring()
else:
declaration = ' '.join([
self.create_template_prefix(node),
''.join(n.astext() for n in self.render(node.get_type())),
name,
node.get_argsstring()
])
nodes = self.handle_declaration(node, declaration)
return nodes
else:
Expand Down

0 comments on commit 5a15303

Please sign in to comment.