(self, method: Method)
| 385 | yield self.generate_method(method) |
| 386 | |
| 387 | def generate_method(self, method: Method): |
| 388 | has_kw_only = method.extra_kwargs or self.has_keep_attrs |
| 389 | |
| 390 | template_kwargs = dict( |
| 391 | obj=self.datastructure.name, |
| 392 | method=method.name, |
| 393 | keep_attrs=( |
| 394 | "\n keep_attrs: bool | None = None," |
| 395 | if self.has_keep_attrs |
| 396 | else "" |
| 397 | ), |
| 398 | kw_only="\n *," if has_kw_only else "", |
| 399 | ) |
| 400 | |
| 401 | if method.extra_kwargs: |
| 402 | extra_kwargs = "\n " + "\n ".join( |
| 403 | [kwarg.kwarg for kwarg in method.extra_kwargs if kwarg.kwarg] |
| 404 | ) |
| 405 | else: |
| 406 | extra_kwargs = "" |
| 407 | |
| 408 | yield self._template_signature.format( |
| 409 | **template_kwargs, |
| 410 | extra_kwargs=extra_kwargs, |
| 411 | ) |
| 412 | |
| 413 | for text in [ |
| 414 | self._dim_docstring.format(method=method.name, cls=self.cls), |
| 415 | *(kwarg.docs for kwarg in method.extra_kwargs if kwarg.docs), |
| 416 | _KEEP_ATTRS_DOCSTRING if self.has_keep_attrs else None, |
| 417 | _KWARGS_DOCSTRING.format(method=method.name), |
| 418 | ]: |
| 419 | if text: |
| 420 | yield textwrap.indent(text, 8 * " ") |
| 421 | |
| 422 | yield TEMPLATE_RETURNS.format(**template_kwargs) |
| 423 | |
| 424 | # we want Dataset.count to refer to DataArray.count |
| 425 | # but we also want DatasetGroupBy.count to refer to Dataset.count |
| 426 | # The generic aggregations have self.cls == '' |
| 427 | others = ( |
| 428 | self.datastructure.see_also_modules |
| 429 | if self.cls == "" |
| 430 | else (self.datastructure.name,) |
| 431 | ) |
| 432 | see_also_methods_from_modules = ( |
| 433 | " " * 8 + f"{mod}.{method.name}" |
| 434 | for mod in (method.see_also_modules + others) |
| 435 | ) |
| 436 | see_also_methods_from_methods = ( |
| 437 | " " * 8 + f"{self.datastructure.name}.{method}" |
| 438 | for method in method.see_also_methods |
| 439 | ) |
| 440 | see_also_methods = "\n".join( |
| 441 | [*see_also_methods_from_modules, *see_also_methods_from_methods] |
| 442 | ) |
| 443 | # Fixes broken links mentioned in #8055 |
| 444 | yield TEMPLATE_SEE_ALSO.format( |
no test coverage detected