Returns true if the only way to set the docstring of `obj` from python is via add_docstring. This function errs on the side of being overly conservative.
(obj)
| 463 | |
| 464 | |
| 465 | def _needs_add_docstring(obj): |
| 466 | """ |
| 467 | Returns true if the only way to set the docstring of `obj` from python is |
| 468 | via add_docstring. |
| 469 | |
| 470 | This function errs on the side of being overly conservative. |
| 471 | """ |
| 472 | Py_TPFLAGS_HEAPTYPE = 1 << 9 |
| 473 | |
| 474 | if isinstance(obj, (types.FunctionType, types.MethodType, property)): |
| 475 | return False |
| 476 | |
| 477 | if isinstance(obj, type) and obj.__flags__ & Py_TPFLAGS_HEAPTYPE: |
| 478 | return False |
| 479 | |
| 480 | return True |
| 481 | |
| 482 | |
| 483 | def _add_docstring(obj, doc, warn_on_python): |