On Friday, June 10, 2011 7:30:06 PM UTC-7, Steven D#39;Aprano wrote:
Carl, I'm not exactly sure what your opposition is about here. Others
have already given real-world use cases for where inheriting docstrings
would be useful and valuable. Do you think that they are wrong? If so,
you
Carl Banks wrote:
Presumably, the reason you are overriding a method in a subclass
is to change its behavior;
Not always true by any means, and maybe not even usually true.
Consider overriding for the purpose of implementing an abstract
method, or because something about the internal
Carl Banks wrote:
x = random.choice([Triange(),Square()])
print x.draw.__doc__ # prints Draws a shape
Quick, what shape is x.draw() going to draw?
Your debugging code is insufficient. It should include
print type(x)
and then it will be obvious what shape is going to get
drawn.
--
Greg
Eric Snow wrote:
But for method objects (really a wrapper for
bound functions) would it change the __doc__ of the wrapper or of the
bound function?
You probably wouldn't want to change the __doc__ of a method
wrapper; instead you'd make sure you got hold of the underlying
function first. So
On Fri, 10 Jun 2011 07:33:34 +1000, Ben Finney wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
It's an unnecessary restriction, as far as I'm concerned, but an old
one.
Well, it's incompatible with the Python compiler I keep in my head. Have
these developers no
On Thu, 09 Jun 2011 23:59:08 -0400, Terry Reedy wrote:
On 6/9/2011 9:12 PM, Carl Banks wrote:
Presumably, the reason you are overriding a method in a subclass is to
change its behavior; I'd expect an inherited docstring to be inaccurate
more often than not. So I'd be -1 on automatically
On Thu, 09 Jun 2011 20:36:53 -0700, Carl Banks wrote:
x = random.choice([Triange(),Square()]) print x.draw.__doc__ # prints
Draws a shape
Quick, what shape is x.draw() going to draw?
That's easy... it will draw a type(x).__name__.
I think this not a terribly convincing argument. I don't
On 06/09/2011 01:22 AM, Eric Snow wrote:
Sometimes when using class inheritance, I want the overriding methods
of the subclass to get the docstring of the matching method in the
base class. You can do this with decorators (after the class
definition), with class decorators, and with metaclasses
On Thu, 09 Jun 2011 00:22:54 -0600, Eric Snow wrote:
Sometimes when using class inheritance, I want the overriding methods of
the subclass to get the docstring of the matching method in the base
class. You can do this with decorators (after the class definition),
with class decorators, and
On Fri, Jun 10, 2011 at 5:05 AM, Tim Chase
python.l...@tim.thechases.com wrote:
On 06/09/2011 01:22 AM, Eric Snow wrote:
Sometimes when using class inheritance, I want the overriding methods
of the subclass to get the docstring of the matching method in the
base class. You can do this with
On Fri, Jun 10, 2011 at 10:47 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Here's some Python 3 code that uses a factory function as a metaclass to
inherit docstrings. Give the class a docstring of an empty string, and it
will be inherited from the first superclass found with
On Fri, 10 Jun 2011 16:47:03 +, Steven D'Aprano wrote:
On Thu, 09 Jun 2011 00:22:54 -0600, Eric Snow wrote:
Sometimes when using class inheritance, I want the overriding methods
of the subclass to get the docstring of the matching method in the base
class. You can do this with
On Fri, Jun 10, 2011 at 10:55 AM, Eric Snow ericsnowcurren...@gmail.com wrote:
The only problem, as seen in the last line, is that the __doc__ on
instances is not inherited on instances of the class. Object
attribute lookup only looks to the type's __dict__ for inheritance,
and not the
On Fri, 10 Jun 2011 11:01:41 -0600, Eric Snow wrote:
On Fri, Jun 10, 2011 at 10:47 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Here's some Python 3 code that uses a factory function as a metaclass
to inherit docstrings. Give the class a docstring of an empty string,
and
FYI, I started this topic up on python-ideas, as it seemed valid
enough from the responses I've gotten here [1].
-eric
[1] http://mail.python.org/pipermail/python-ideas/2011-June/010473.html
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, Jun 10, 2011 at 11:26 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
Everybody always focuses so much on properties and forgets that you
can also just write your own descriptors.
I'm so glad that you pointed this out. I totally forgot that
properties simply returned themselves if not
On Thursday, June 9, 2011 10:18:34 PM UTC-7, Ben Finney wrote:
[snip example where programmer is expected to consult class docstring to infer
what a method does]
There's nothing wrong with the docstring for a method referring to the
context within which the method is defined.
Whenever
On Friday, June 10, 2011 2:51:20 AM UTC-7, Steven D#39;Aprano wrote:
On Thu, 09 Jun 2011 20:36:53 -0700, Carl Banks wrote:
Put it this way: if Python doesn't automatically inherit docstrings, the
worst that can happen is missing information. If Python does inherit
docstrings, it can lead
On Thu, Jun 9, 2011 at 12:22 AM, Eric Snow ericsnowcurren...@gmail.com wrote:
Sometimes when using class inheritance, I want the overriding methods
of the subclass to get the docstring of the matching method in the
base class. You can do this with decorators (after the class
definition), with
On Fri, 10 Jun 2011 14:46:06 -0700, Carl Banks wrote:
On Friday, June 10, 2011 2:51:20 AM UTC-7, Steven D#39;Aprano wrote:
On Thu, 09 Jun 2011 20:36:53 -0700, Carl Banks wrote:
Put it this way: if Python doesn't automatically inherit docstrings,
the worst that can happen is missing
Sometimes when using class inheritance, I want the overriding methods
of the subclass to get the docstring of the matching method in the
base class. You can do this with decorators (after the class
definition), with class decorators, and with metaclasses [1].
However, I was hoping for a way to
Eric Snow ericsnowcurren...@gmail.com writes:
p.s. Am I missing something or can you really not change the docstring
of a class? I was thinking about the idea of inheriting class
docstrings too.
The docstring of an object (whether function or class or module) is the
object's ‘__doc__’
On Thu, Jun 9, 2011 at 12:37 AM, Ben Finney ben+pyt...@benfinney.id.au wrote:
Eric Snow ericsnowcurren...@gmail.com writes:
p.s. Am I missing something or can you really not change the docstring
of a class? I was thinking about the idea of inheriting class
docstrings too.
The docstring of
On Thursday, June 9, 2011 12:13:06 AM UTC-7, Eric Snow wrote:
On Thu, Jun 9, 2011 at 12:37 AM, Ben Finney ben+p...@benfinney.id.au wrote:
So, it's even possible to do what you ask without decorators at all:
class Foo(object):
def frob(self):
Frobnicate thyself.
Eric Snow ericsnowcurren...@gmail.com writes:
AttributeError: attribute '__doc__' of 'type' objects is not writable
That is on 3.3.
Well, that sucks :-(
Where can we see the discussion of that change before it was
implemented?
I'm just looking for a way to do it with decorators in the
Ben Finney ben+pyt...@benfinney.id.au wrote:
Eric Snow ericsnowcurren...@gmail.com writes:
AttributeError: attribute '__doc__' of 'type' objects is not writable
That is on 3.3.
Well, that sucks :-(
Where can we see the discussion of that change before it was
implemented?
Change?
On Thu, 09 Jun 2011 17:44:32 +1000, Ben Finney wrote:
Eric Snow ericsnowcurren...@gmail.com writes:
AttributeError: attribute '__doc__' of 'type' objects is not writable
That is on 3.3.
Well, that sucks :-(
Where can we see the discussion of that change before it was
implemented?
It
Eric Snow wrote:
p.s. Am I missing something or can you really not change the docstring
of a class? I was thinking about the idea of inheriting class
docstrings too.
8
module level docstring
def func():
function level docstring
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
On Thu, 09 Jun 2011 17:44:32 +1000, Ben Finney wrote:
Eric Snow ericsnowcurren...@gmail.com writes:
AttributeError: attribute '__doc__' of 'type' objects is not writable
That is on 3.3.
Well, that sucks :-(
Where
IMO, it shouldn't be necessary to explicitly copy docstrings
around like this in the first place. Either it should happen
automatically, or help() should be smart enough to look up
the inheritance hierarchy when given a method that doesn't
have a docstring of its own.
Unfortunately, since
On Thu, Jun 9, 2011 at 4:27 PM, Gregory Ewing
greg.ew...@canterbury.ac.nz wrote:
IMO, it shouldn't be necessary to explicitly copy docstrings
around like this in the first place. Either it should happen
automatically, or help() should be smart enough to look up
the inheritance hierarchy when
Gregory Ewing greg.ew...@canterbury.ac.nz writes:
IMO, it shouldn't be necessary to explicitly copy docstrings around
like this in the first place. Either it should happen automatically,
or help() should be smart enough to look up the inheritance hierarchy
when given a method that doesn't
On Thu, Jun 9, 2011 at 10:10 AM, Ethan Furman et...@stoneleaf.us wrote:
Eric Snow wrote:
p.s. Am I missing something or can you really not change the docstring
of a class? I was thinking about the idea of inheriting class
docstrings too.
On Thu, Jun 9, 2011 at 5:23 PM, Ben Finney ben+pyt...@benfinney.id.au wrote:
Gregory Ewing greg.ew...@canterbury.ac.nz writes:
IMO, it shouldn't be necessary to explicitly copy docstrings around
like this in the first place. Either it should happen automatically,
or help() should be smart
On Thursday, June 9, 2011 3:27:36 PM UTC-7, Gregory Ewing wrote:
IMO, it shouldn't be necessary to explicitly copy docstrings
around like this in the first place. Either it should happen
automatically, or help() should be smart enough to look up
the inheritance hierarchy when given a method
Carl Banks pavlovevide...@gmail.com writes:
Presumably, the reason you are overriding a method in a subclass is to
change its behavior; I'd expect an inherited docstring to be
inaccurate more often than not.
In which case the onus is on the programmer implementing different
behaviour to also
On Thu, Jun 9, 2011 at 7:12 PM, Carl Banks pavlovevide...@gmail.com wrote:
On Thursday, June 9, 2011 3:27:36 PM UTC-7, Gregory Ewing wrote:
IMO, it shouldn't be necessary to explicitly copy docstrings
around like this in the first place. Either it should happen
automatically, or help() should
On Thursday, June 9, 2011 6:42:44 PM UTC-7, Ben Finney wrote:
Carl Banks
writes:
Presumably, the reason you are overriding a method in a subclass is to
change its behavior; I'd expect an inherited docstring to be
inaccurate more often than not.
In which case the onus is on the
On Thursday, June 9, 2011 7:37:19 PM UTC-7, Eric Snow wrote:
When I write ABCs to capture an interface, I usually put the
documentation in the docstrings there. Then when I implement I want
to inherit the docstrings. Implicit docstring inheritance for
abstract base classes would meet my
On 6/9/2011 9:12 PM, Carl Banks wrote:
Presumably, the reason you are overriding a method in a subclass is to change
its behavior; I'd expect an inherited docstring to be inaccurate more often
than not. So I'd be -1 on automatically inheriting them.
However, I'd be +1 easily on a little
On Thu, Jun 9, 2011 at 9:59 PM, Terry Reedy tjre...@udel.edu wrote:
On 6/9/2011 9:12 PM, Carl Banks wrote:
Presumably, the reason you are overriding a method in a subclass is to
change its behavior; I'd expect an inherited docstring to be inaccurate more
often than not. So I'd be -1 on
Carl Banks pavlovevide...@gmail.com writes:
On Thursday, June 9, 2011 7:37:19 PM UTC-7, Eric Snow wrote:
When I write ABCs to capture an interface, I usually put the
documentation in the docstrings there. Then when I implement I want
to inherit the docstrings. Implicit docstring
Ben Finney ben+pyt...@benfinney.id.au writes:
class Square(Shape):
An equal-sided quadrilateral polygon.
That this docstring is imprecise (it describes any rhombus, not
necessarily a square) is something I hope no-one else notices or draws
attention to.
Oh, darn.
--
\ “The sun
On Fri, Jun 10, 2011 at 3:25 PM, Ben Finney ben+pyt...@benfinney.id.au wrote:
Ben Finney ben+pyt...@benfinney.id.au writes:
class Square(Shape):
An equal-sided quadrilateral polygon.
That this docstring is imprecise (it describes any rhombus, not
necessarily a square) is something I
44 matches
Mail list logo