r"""Given a docstring, split off the header and parse the function details. For example the docstring of tf.nn.relu: '''Computes rectified linear: `max(features, 0)`. Args: features: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `int64`, `uint8`, `
(docstring)
| 530 | |
| 531 | |
| 532 | def _parse_function_details(docstring): |
| 533 | r"""Given a docstring, split off the header and parse the function details. |
| 534 | |
| 535 | For example the docstring of tf.nn.relu: |
| 536 | |
| 537 | '''Computes rectified linear: `max(features, 0)`. |
| 538 | |
| 539 | Args: |
| 540 | features: A `Tensor`. Must be one of the following types: `float32`, |
| 541 | `float64`, `int32`, `int64`, `uint8`, `int16`, `int8`, `uint16`, |
| 542 | `half`. |
| 543 | name: A name for the operation (optional). |
| 544 | |
| 545 | Returns: |
| 546 | A `Tensor`. Has the same type as `features`. |
| 547 | ''' |
| 548 | |
| 549 | This is parsed, and returned as: |
| 550 | |
| 551 | ``` |
| 552 | ('Computes rectified linear: `max(features, 0)`.\n\n', [ |
| 553 | _FunctionDetail( |
| 554 | keyword='Args', |
| 555 | header='', |
| 556 | items=[ |
| 557 | ('features', ' A `Tensor`. Must be ...'), |
| 558 | ('name', ' A name for the operation (optional).\n\n')]), |
| 559 | _FunctionDetail( |
| 560 | keyword='Returns', |
| 561 | header=' A `Tensor`. Has the same type as `features`.', |
| 562 | items=[]) |
| 563 | ]) |
| 564 | ``` |
| 565 | |
| 566 | Args: |
| 567 | docstring: The docstring to parse |
| 568 | |
| 569 | Returns: |
| 570 | A (header, function_details) pair, where header is a string and |
| 571 | function_details is a (possibly empty) list of `_FunctionDetail` objects. |
| 572 | """ |
| 573 | |
| 574 | detail_keywords = '|'.join([ |
| 575 | 'Args', 'Arguments', 'Fields', 'Returns', 'Yields', 'Raises', 'Attributes' |
| 576 | ]) |
| 577 | tag_re = re.compile('(?<=\n)(' + detail_keywords + '):\n', re.MULTILINE) |
| 578 | parts = tag_re.split(docstring) |
| 579 | |
| 580 | # The first part is the main docstring |
| 581 | docstring = parts[0] |
| 582 | |
| 583 | # Everything else alternates keyword-content |
| 584 | pairs = list(_gen_pairs(parts[1:])) |
| 585 | |
| 586 | function_details = [] |
| 587 | item_re = re.compile(r'^ ? ?(\*?\*?\w[\w.]*?\s*):\s', re.MULTILINE) |
| 588 | |
| 589 | for keyword, content in pairs: |
no test coverage detected