Skip to content

Commit c298b0a

Browse files
committed
Automatically add function variants specified as B{...}
1 parent e6d0ca0 commit c298b0a

File tree

3 files changed

+4140
-265
lines changed

3 files changed

+4140
-265
lines changed

bpystubgen/directives.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def parse_args(self, args: arguments, fields: Mapping[str, str]) -> (OrderedDict
259259

260260

261261
class FunctionDirective(FunctionLikeDirective):
262+
_alias_pattern = re.compile("^B{([^}]+)}")
262263

263264
def run(self) -> List[Node]:
264265
document = self.state_machine.document
@@ -310,6 +311,19 @@ def run(self) -> List[Node]:
310311

311312
elems.append(elem)
312313
elems.extend(messages)
314+
315+
alias_match = self._alias_pattern.match(ds.docstring.astext())
316+
317+
if alias_match:
318+
alias_text = alias_match.group(1)
319+
alias_text.replace(" and ", ", ")
320+
321+
for alias in map(lambda a: a.strip(), alias_text.split(",")):
322+
copy = elem.deepcopy()
323+
copy.name = alias
324+
325+
elems.append(copy)
326+
313327
except SyntaxError:
314328
msg = reporter.error(f"Invalid function signature: {line}", base_node=self.state.parent)
315329
elems.append(msg)
@@ -359,7 +373,7 @@ def run(self) -> List[Node]:
359373

360374
ctor += docstring
361375

362-
for arg in args.values():
376+
for arg in iter(args.values()):
363377
ctor += arg
364378

365379
elem.insert(0, ctor)

0 commit comments

Comments
 (0)