Check reStructuredText formatting of docstrings Parameters ---------- module : ModuleType names : set Returns ------- result : list List of [(module_name, success_flag, output),...]
(module, names, dots=True)
| 519 | |
| 520 | |
| 521 | def check_rest(module, names, dots=True): |
| 522 | """ |
| 523 | Check reStructuredText formatting of docstrings |
| 524 | |
| 525 | Parameters |
| 526 | ---------- |
| 527 | module : ModuleType |
| 528 | |
| 529 | names : set |
| 530 | |
| 531 | Returns |
| 532 | ------- |
| 533 | result : list |
| 534 | List of [(module_name, success_flag, output),...] |
| 535 | """ |
| 536 | |
| 537 | try: |
| 538 | skip_types = (dict, str, unicode, float, int) |
| 539 | except NameError: |
| 540 | # python 3 |
| 541 | skip_types = (dict, str, float, int) |
| 542 | |
| 543 | |
| 544 | results = [] |
| 545 | |
| 546 | if module.__name__[6:] not in OTHER_MODULE_DOCS: |
| 547 | results += [(module.__name__,) + |
| 548 | validate_rst_syntax(inspect.getdoc(module), |
| 549 | module.__name__, dots=dots)] |
| 550 | |
| 551 | for name in names: |
| 552 | full_name = module.__name__ + '.' + name |
| 553 | obj = getattr(module, name, None) |
| 554 | |
| 555 | if obj is None: |
| 556 | results.append((full_name, False, "%s has no docstring" % (full_name,))) |
| 557 | continue |
| 558 | elif isinstance(obj, skip_types): |
| 559 | continue |
| 560 | |
| 561 | if inspect.ismodule(obj): |
| 562 | text = inspect.getdoc(obj) |
| 563 | else: |
| 564 | try: |
| 565 | text = str(get_doc_object(obj)) |
| 566 | except Exception: |
| 567 | import traceback |
| 568 | results.append((full_name, False, |
| 569 | "Error in docstring format!\n" + |
| 570 | traceback.format_exc())) |
| 571 | continue |
| 572 | |
| 573 | m = re.search("([\x00-\x09\x0b-\x1f])", text) |
| 574 | if m: |
| 575 | msg = ("Docstring contains a non-printable character %r! " |
| 576 | "Maybe forgot r\"\"\"?" % (m.group(1),)) |
| 577 | results.append((full_name, False, msg)) |
| 578 | continue |
no test coverage detected