|
435 | 435 | "@delegates(_docments)\n",
|
436 | 436 | "def docments(elt, full=False, **kwargs):\n",
|
437 | 437 | " \"Generates a `docment`\"\n",
|
| 438 | + " r = {}\n", |
| 439 | + " params = set(signature(elt).parameters)\n", |
| 440 | + " params.add('return')\n", |
| 441 | + "\n", |
438 | 442 | " def _update_docments(f, r):\n",
|
439 | 443 | " if hasattr(f, '__delwrap__'): _update_docments(f.__delwrap__, r)\n",
|
440 | 444 | " r.update({k:v for k,v in _docments(f, **kwargs).items()\n",
|
441 |
| - " if full or v.get('docment',None)})\n", |
| 445 | + " if k in params and (full or v.get('docment',None))})\n", |
442 | 446 | "\n",
|
443 |
| - " r = {}\n", |
444 | 447 | " _update_docments(elt, r)\n",
|
445 | 448 | " if not full: r = {k:v['docment'] for k,v in r.items()}\n",
|
446 | 449 | " return AttrDict(r)"
|
|
462 | 465 | "data": {
|
463 | 466 | "text/markdown": [
|
464 | 467 | "```json\n",
|
465 |
| - "{ 'a': 'the 1st number to add',\n", |
466 |
| - " 'b': 'the 2nd number to add',\n", |
467 |
| - " 'return': 'the result of adding `a` to `b`'}\n", |
| 468 | + "{ 'a': 'The first operand',\n", |
| 469 | + " 'b': 'This is the second of the operands to the *addition* operator.\\n'\n", |
| 470 | + " 'Note that passing a negative value here is the equivalent of the '\n", |
| 471 | + " '*subtraction* operator.',\n", |
| 472 | + " 'return': \"The result is calculated using Python's builtin `+` operator.\"}\n", |
468 | 473 | "```"
|
469 | 474 | ],
|
470 | 475 | "text/plain": [
|
471 |
| - "{'a': 'the 1st number to add',\n", |
472 |
| - " 'b': 'the 2nd number to add',\n", |
473 |
| - " 'return': 'the result of adding `a` to `b`'}" |
| 476 | + "{'a': 'The first operand',\n", |
| 477 | + " 'b': 'This is the second of the operands to the *addition* operator.\\nNote that passing a negative value here is the equivalent of the *subtraction* operator.',\n", |
| 478 | + " 'return': \"The result is calculated using Python's builtin `+` operator.\"}" |
474 | 479 | ]
|
475 | 480 | },
|
476 | 481 | "execution_count": null,
|
|
500 | 505 | "```json\n",
|
501 | 506 | "{ 'a': { 'anno': 'int',\n",
|
502 | 507 | " 'default': <class 'inspect._empty'>,\n",
|
503 |
| - " 'docment': 'the 1st number to add'},\n", |
504 |
| - " 'b': { 'anno': <class 'int'>,\n", |
505 |
| - " 'default': 0,\n", |
506 |
| - " 'docment': 'the 2nd number to add'},\n", |
| 508 | + " 'docment': 'The first operand'},\n", |
| 509 | + " 'b': { 'anno': 'int',\n", |
| 510 | + " 'default': <class 'inspect._empty'>,\n", |
| 511 | + " 'docment': 'This is the second of the operands to the *addition* '\n", |
| 512 | + " 'operator.\\n'\n", |
| 513 | + " 'Note that passing a negative value here is the equivalent '\n", |
| 514 | + " 'of the *subtraction* operator.'},\n", |
507 | 515 | " 'return': { 'anno': 'int',\n",
|
508 | 516 | " 'default': <class 'inspect._empty'>,\n",
|
509 |
| - " 'docment': 'the result of adding `a` to `b`'}}\n", |
| 517 | + " 'docment': \"The result is calculated using Python's builtin `+` \"\n", |
| 518 | + " 'operator.'}}\n", |
510 | 519 | "```"
|
511 | 520 | ],
|
512 | 521 | "text/plain": [
|
513 |
| - "{'a': {'docment': 'the 1st number to add',\n", |
| 522 | + "{'a': {'docment': 'The first operand',\n", |
| 523 | + " 'anno': 'int',\n", |
| 524 | + " 'default': inspect._empty},\n", |
| 525 | + " 'b': {'docment': 'This is the second of the operands to the *addition* operator.\\nNote that passing a negative value here is the equivalent of the *subtraction* operator.',\n", |
514 | 526 | " 'anno': 'int',\n",
|
515 | 527 | " 'default': inspect._empty},\n",
|
516 |
| - " 'b': {'docment': 'the 2nd number to add', 'anno': int, 'default': 0},\n", |
517 |
| - " 'return': {'docment': 'the result of adding `a` to `b`',\n", |
| 528 | + " 'return': {'docment': \"The result is calculated using Python's builtin `+` operator.\",\n", |
518 | 529 | " 'anno': 'int',\n",
|
519 | 530 | " 'default': inspect._empty}}"
|
520 | 531 | ]
|
|
546 | 557 | "```json\n",
|
547 | 558 | "{ 'anno': <class 'int'>,\n",
|
548 | 559 | " 'default': <class 'inspect._empty'>,\n",
|
549 |
| - " 'docment': 'the 1st number to add'}\n", |
| 560 | + " 'docment': 'The first operand'}\n", |
550 | 561 | "```"
|
551 | 562 | ],
|
552 | 563 | "text/plain": [
|
553 |
| - "{'docment': 'the 1st number to add', 'anno': int, 'default': inspect._empty}" |
| 564 | + "{'docment': 'The first operand', 'anno': int, 'default': inspect._empty}" |
554 | 565 | ]
|
555 | 566 | },
|
556 | 567 | "execution_count": null,
|
|
0 commit comments