Skip to content

Commit

Permalink
Procedures: move 'build signature' to _signature() method, use in repr
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Sep 12, 2024
1 parent 45beb7b commit 1f135fa
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions asteval/astutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,18 @@ def _getdoc(self):

def __repr__(self):
"""TODO: docstring in magic method."""
sig = self._signature()
rep = f"<Procedure {sig}>"
doc = self._getdoc()
if doc is not None:
rep = f"{rep}\n {doc}"
return rep

def _signature(self):
"call signature"
sig = ""
if len(self.argnames) > 0:
sig = sig + ', '.join(self.argnames)
sig = sig + ', '.join(self.argnames)
if self.vararg is not None:
sig = sig + f"*{self.vararg}"
if len(self.kwargs) > 0:
Expand All @@ -544,13 +553,9 @@ def __repr__(self):
_kw = [f"{k}={v}" for k, v in self.kwargs]
sig = f"{sig}{', '.join(_kw)}"

if self.varkws is not None:
sig = f"%sig, **{self.varkws}"
sig = f"<Procedure {self.name}({sig})>"
doc = self._getdoc()
if doc is not None:
sig = f"{sig}\n {doc}"
return sig
if self.varkws is not None:
sig = f"{sig}, **{self.varkws}"
return f"{self.name}({sig})"

def __call__(self, *args, **kwargs):
"""TODO: docstring in public method."""
Expand Down

0 comments on commit 1f135fa

Please sign in to comment.