GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — `inspect.getdoc()` failing to return docstring for cached_property for subclass that overrides code but not docstring · Issue #131116 · python/cpython Closed Labels 3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement DescriptionBug reportBug description:When a child/sub-class inherits a method from its parent/base-class, However, this is failing when the method has the from functools import cached_property import inspect class Parent: @cached_property def foo(self): "this is the docstring for foo" return 1 class Child(Parent): @cached_property def foo(self): ... assert inspect.getdoc(Child.foo) == inspect.getdoc(Parent.foo) # fails but we want this to be True I did my best to test this across a variety of similar things and this was the only case where I found the docstring to not be inherited. I tested across methods, properties (with the The below test code shows passes for all those other scenarios but only fails on from functools import cached_property import inspect import unittest class TestMatchingDocstrings(unittest.TestCase): def setUp(self): self.parent_class = ParentClass self.child_class = ChildClass def compare_docstrings(self, attrname): parent_attr = getattr(self.parent_class, attrname) parent_docstring = inspect.getdoc(parent_attr) child_attr = getattr(self.child_class, attrname) child_docstring = inspect.getdoc(child_attr) self.assertEqual(parent_docstring, child_docstring) def test_method_defined_in_parent_only(self): self.compare_docstrings("method_defined_in_parent_only") def test_method_defined_in_parent_and_child(self): self.compare_docstrings("method_defined_in_parent_and_child") def test_property_defined_in_parent_only(self): self.compare_docstrings("property_defined_in_parent_only") def test_property_defined_in_parent_and_child(self): self.compare_docstrings("property_defined_in_parent_and_child") def test_cached_property_defined_in_parent_only(self): self.compare_docstrings("cached_property_defined_in_parent_only") def test_cached_property_defined_in_parent_and_child(self): self.compare_docstrings("cached_property_defined_in_parent_and_child") def test_static_method_defined_in_parent_only(self): self.compare_docstrings("static_method_defined_in_parent_only") def test_static_method_defined_in_parent_and_child(self): self.compare_docstrings("static_method_defined_in_parent_and_child") def test_class_method_defined_in_parent_only(self): self.compare_docstrings("class_method_defined_in_parent_only") def test_class_method_defined_in_parent_and_child(self): self.compare_docstrings("class_method_defined_in_parent_and_child") class ParentClass: def method_defined_in_parent_only(self): "This is a method in the parent only" def method_defined_in_parent_and_child(self): "This is a method in the parent and child" @property def property_defined_in_parent_only(self): "This is a property with the decorator in the parent only" @property def property_defined_in_parent_and_child(self): "This is a property with the decorator in the parent and child" @cached_property def cached_property_defined_in_parent_only(self): "This is a cached property with the decorator in the parent only" @cached_property def cached_property_defined_in_parent_and_child(self): "This is a cached property with the decorator in the parent and child" @staticmethod def static_method_defined_in_parent_only(): "This is a static method with the decorator in the parent only" @staticmethod def static_method_defined_in_parent_and_child(): "This is a static method with the decorator in the parent and child" @classmethod def class_method_defined_in_parent_only(cls): "This is a class method with the decorator in the parent only" @classmethod def class_method_defined_in_parent_and_child(cls): "This is a class method with the decorator in the parent and child" class ChildClass(ParentClass): def method_defined_in_parent_and_child(self): ... @property def property_defined_in_parent_and_child(self): ... @cached_property def cached_property_defined_in_parent_and_child(self): ... @staticmethod def static_method_defined_in_parent_and_child(): ... @classmethod def class_method_defined_in_parent_and_child(cls): ... if __name__ == "__main__": unittest.main() CPython versions tested on:3.9, 3.10, 3.11, 3.12, 3.13, 3.14 Operating systems tested on:Windows Linked PRsActivity
MetadataMetadataAssigneesLabels3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement Projects
MilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |