[Python-ideas] inheriting docstrings and mutable docstings for classes
Steven D'Aprano
steve at pearwood.info
Fri Jun 10 13:22:15 CEST 2011
David Stanek wrote:
> On Fri, Jun 10, 2011 at 3:04 AM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:
>
>> Maybe the best thing would be for the inherited docstring
>> to get put into a different property, such as __basedoc__.
>> Then tools that examine docstrings can decide for themselves
>> whether using inherited docstrings makes sense.
>>
>>
> How would a tool know if the behavior of a method changed without analyzing
> the code? I think this could very easily lead to a situation where a
> project's generated documentation is incorrect.
That's the developer's problem, and no different from any other case
where you inherit data without ensuring it is the correct data.
class Parrot:
colour = 'green'
def speak(self):
return "Polly wants a cracker."
class NorwegianBlue(Parrot):
def speak(self):
return "I'm pining for the fjords."
assert NorwegianBlue().colour == 'blue' # oops!
--
Steven
More information about the Python-ideas
mailing list