Writes a function call to the stream for the current node. A leading comma is added automatically. The extra keyword arguments may not include python keywords otherwise a syntax error could occur. The extra keyword arguments should be given as python dict.
(
self,
node: t.Union[nodes.Call, nodes.Filter, nodes.Test],
frame: Frame,
extra_kwargs: t.Optional[t.Mapping[str, t.Any]] = None,
)
| 479 | self._last_line = node.lineno |
| 480 | |
| 481 | def signature( |
| 482 | self, |
| 483 | node: t.Union[nodes.Call, nodes.Filter, nodes.Test], |
| 484 | frame: Frame, |
| 485 | extra_kwargs: t.Optional[t.Mapping[str, t.Any]] = None, |
| 486 | ) -> None: |
| 487 | """Writes a function call to the stream for the current node. |
| 488 | A leading comma is added automatically. The extra keyword |
| 489 | arguments may not include python keywords otherwise a syntax |
| 490 | error could occur. The extra keyword arguments should be given |
| 491 | as python dict. |
| 492 | """ |
| 493 | # if any of the given keyword arguments is a python keyword |
| 494 | # we have to make sure that no invalid call is created. |
| 495 | kwarg_workaround = any( |
| 496 | is_python_keyword(t.cast(str, k)) |
| 497 | for k in chain((x.key for x in node.kwargs), extra_kwargs or ()) |
| 498 | ) |
| 499 | |
| 500 | for arg in node.args: |
| 501 | self.write(", ") |
| 502 | self.visit(arg, frame) |
| 503 | |
| 504 | if not kwarg_workaround: |
| 505 | for kwarg in node.kwargs: |
| 506 | self.write(", ") |
| 507 | self.visit(kwarg, frame) |
| 508 | if extra_kwargs is not None: |
| 509 | for key, value in extra_kwargs.items(): |
| 510 | self.write(f", {key}={value}") |
| 511 | if node.dyn_args: |
| 512 | self.write(", *") |
| 513 | self.visit(node.dyn_args, frame) |
| 514 | |
| 515 | if kwarg_workaround: |
| 516 | if node.dyn_kwargs is not None: |
| 517 | self.write(", **dict({") |
| 518 | else: |
| 519 | self.write(", **{") |
| 520 | for kwarg in node.kwargs: |
| 521 | self.write(f"{kwarg.key!r}: ") |
| 522 | self.visit(kwarg.value, frame) |
| 523 | self.write(", ") |
| 524 | if extra_kwargs is not None: |
| 525 | for key, value in extra_kwargs.items(): |
| 526 | self.write(f"{key!r}: {value}, ") |
| 527 | if node.dyn_kwargs is not None: |
| 528 | self.write("}, **") |
| 529 | self.visit(node.dyn_kwargs, frame) |
| 530 | self.write(")") |
| 531 | else: |
| 532 | self.write("}") |
| 533 | |
| 534 | elif node.dyn_kwargs is not None: |
| 535 | self.write(", **") |
| 536 | self.visit(node.dyn_kwargs, frame) |
| 537 | |
| 538 | def pull_dependencies(self, nodes: t.Iterable[nodes.Node]) -> None: |
no test coverage detected