bpo-38603: Inherit docstrings in dynamically generated subclasses if possible #16957
+32
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Currently,
inspect.getdoc()fails to inherit docstrings in dynamicallygenerated subclasses, such as
because
inspect._findclass()tries to find the baseclass by parsing
subclass.method.__qualname__which is"make_subclass.<locals>.subclass.method"and chokes over.<locals>..In the case where the method does rely on
super(), there is anotherway we can go back to the "owning" class of the method: by looking up
the contents of the
__class__cell (which is set up to make 0-argsuper()). This approach is implemented by this PR.
Perhaps a
__class__cell could even be set up (in a separate patch)for all methods defined in dynamically created subclasses (i.e. whose
__qualname__includes.<locals>.), to help with introspection?https://bugs.python.org/issue38603