[Python-Dev] [Python-checkins] cpython: asyncio.events: Use __slots__ in Handle and TimerHandle

Ethan Furman ethan at stoneleaf.us
Thu Feb 13 00:10:25 CET 2014


On 02/12/2014 02:02 PM, yury.selivanov wrote:
> http://hg.python.org/cpython/rev/920304e1f36b
> changeset:   89175:920304e1f36b
> user:        Yury Selivanov <yselivanov at sprymix.com>
> date:        Wed Feb 12 17:01:52 2014 -0500
> summary:
>    asyncio.events: Use __slots__ in Handle and TimerHandle
>
> files:
>    Lib/asyncio/events.py |  4 ++++
>    1 files changed, 4 insertions(+), 0 deletions(-)
>
>
> diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
> --- a/Lib/asyncio/events.py
> +++ b/Lib/asyncio/events.py
> @@ -19,6 +19,8 @@
>   class Handle:
>       """Object returned by callback registration methods."""
>
> +    __slots__ = ['_callback', '_args', '_cancelled']
> +
>       def __init__(self, callback, args):
>           assert not isinstance(callback, Handle), 'A Handle is not a callback'
>           self._callback = callback
> @@ -46,6 +48,8 @@
>   class TimerHandle(Handle):
>       """Object returned by timed callback registration methods."""
>
> +    __slots__ = ['_when']
> +
>       def __init__(self, when, callback, args):
>           assert when is not None
>           super().__init__(callback, args)

Apologies up front if these are stupid questions, but:

Why __slots__?  Are we going to have so many of these things that memory is an issue?

The asserts in the code -- those are not for checking user input, correct?

--
~Ethan~


More information about the Python-Dev mailing list