Re: [Python-Dev] cpython: asyncio: Fix CoroWrapper (fix my previous commit)
On Thu, 16 Jan 2014 01:55:43 +0100 (CET) victor.stinner <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/f07161c4f3aa changeset: 88494:f07161c4f3aa user: Victor Stinner <victor.stinner@gmail.com> date: Thu Jan 16 01:55:29 2014 +0100 summary: asyncio: Fix CoroWrapper (fix my previous commit)
Add __name__ and __doc__ to __slots__
files: Lib/asyncio/tasks.py | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -32,9 +32,7 @@
class CoroWrapper: - """Wrapper for coroutine in _DEBUG mode.""" - - __slots__ = ['gen', 'func'] + __slots__ = ['gen', 'func', '__name__', '__doc__']
Why did you remove the docstring? Regards Antoine.
Because somehow you can't have a slot named __doc__ *and* a docstring in the class. Try it. (I tried to work around this but didn't get very far.) On Thu, Jan 16, 2014 at 3:40 AM, Antoine Pitrou <solipsis@pitrou.net> wrote:
On Thu, 16 Jan 2014 01:55:43 +0100 (CET) victor.stinner <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/f07161c4f3aa changeset: 88494:f07161c4f3aa user: Victor Stinner <victor.stinner@gmail.com> date: Thu Jan 16 01:55:29 2014 +0100 summary: asyncio: Fix CoroWrapper (fix my previous commit)
Add __name__ and __doc__ to __slots__
files: Lib/asyncio/tasks.py | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -32,9 +32,7 @@
class CoroWrapper: - """Wrapper for coroutine in _DEBUG mode.""" - - __slots__ = ['gen', 'func'] + __slots__ = ['gen', 'func', '__name__', '__doc__']
Why did you remove the docstring?
Regards
Antoine.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (python.org/~guido)
On 16.01.2014 16:57, Guido van Rossum wrote:
Because somehow you can't have a slot named __doc__ *and* a docstring in the class. Try it. (I tried to work around this but didn't get very far.)
That's true for all class attributes. You can't have a slot and a class attribute at the same time. After all the __doc__ string is stored in a class attribute, too.
class Example: ... __slots__ = ("egg",) ... # This doesn't work ... egg = None ... Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: 'egg' in __slots__ conflicts with class variable
class Example: ... """doc""" ... __slots__ = ("__doc__",) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: '__doc__' in __slots__ conflicts with class variable
Yeah the confusing thing is that omitting the docstring fixes it -- the class still has a __doc__ attribute but apparently it comes from the metaclass. :-) I guess you *could* have both a class and an instance __doc__ by making a really clever descriptor, but it seems simpler to just use a comment instead of a docstring. :-) I'll do this now. On Thu, Jan 16, 2014 at 8:14 AM, Christian Heimes <christian@python.org> wrote:
On 16.01.2014 16:57, Guido van Rossum wrote:
Because somehow you can't have a slot named __doc__ *and* a docstring in the class. Try it. (I tried to work around this but didn't get very far.)
That's true for all class attributes. You can't have a slot and a class attribute at the same time. After all the __doc__ string is stored in a class attribute, too.
class Example: ... __slots__ = ("egg",) ... # This doesn't work ... egg = None ... Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: 'egg' in __slots__ conflicts with class variable
class Example: ... """doc""" ... __slots__ = ("__doc__",) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: '__doc__' in __slots__ conflicts with class variable
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (python.org/~guido)
participants (3)
-
Antoine Pitrou
-
Christian Heimes
-
Guido van Rossum