diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-02-09 23:45:44 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-02-09 23:45:44 (GMT) |
commit | dc62b7e261ab88b4ab967ac2ae307eddbfa0ae09 (patch) | |
tree | 0c8878ba52ef21fb7058545b9ca62d1838cf9ccd /Lib | |
parent | 136fea253e438a0db6a1d24d3c23f02fcb64b7c4 (diff) | |
download | cpython-dc62b7e261ab88b4ab967ac2ae307eddbfa0ae09.zip cpython-dc62b7e261ab88b4ab967ac2ae307eddbfa0ae09.tar.gz cpython-dc62b7e261ab88b4ab967ac2ae307eddbfa0ae09.tar.bz2 |
asyncio: Tulip issue 112: Inline make_handle() into Handle constructor
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/base_events.py | 2 | ||||
-rw-r--r-- | Lib/asyncio/events.py | 7 | ||||
-rw-r--r-- | Lib/asyncio/selector_events.py | 4 | ||||
-rw-r--r-- | Lib/asyncio/test_utils.py | 4 | ||||
-rw-r--r-- | Lib/asyncio/unix_events.py | 2 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 4 |
6 files changed, 9 insertions, 14 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index db57ee8..558406c 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -240,7 +240,7 @@ class BaseEventLoop(events.AbstractEventLoop): Any positional arguments after the callback will be passed to the callback when it is called. """ - handle = events.make_handle(callback, args) + handle = events.Handle(callback, args) self._ready.append(handle) return handle diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index 6240019..4c0cbb0 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -20,6 +20,7 @@ class Handle: """Object returned by callback registration methods.""" def __init__(self, callback, args): + assert not isinstance(callback, Handle), 'A Handle is not a callback' self._callback = callback self._args = args self._cancelled = False @@ -42,12 +43,6 @@ class Handle: self = None # Needed to break cycles when an exception occurs. -def make_handle(callback, args): - # TODO: Inline this? Or make it a private EventLoop method? - assert not isinstance(callback, Handle), 'A Handle is not a callback' - return Handle(callback, args) - - class TimerHandle(Handle): """Object returned by timed callback registration methods.""" diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 202c14b..14231c5 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -132,7 +132,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): def add_reader(self, fd, callback, *args): """Add a reader callback.""" - handle = events.make_handle(callback, args) + handle = events.Handle(callback, args) try: key = self._selector.get_key(fd) except KeyError: @@ -167,7 +167,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): def add_writer(self, fd, callback, *args): """Add a writer callback..""" - handle = events.make_handle(callback, args) + handle = events.Handle(callback, args) try: key = self._selector.get_key(fd) except KeyError: diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py index ccb4454..71d69cf 100644 --- a/Lib/asyncio/test_utils.py +++ b/Lib/asyncio/test_utils.py @@ -216,7 +216,7 @@ class TestLoop(base_events.BaseEventLoop): raise AssertionError("Time generator is not finished") def add_reader(self, fd, callback, *args): - self.readers[fd] = events.make_handle(callback, args) + self.readers[fd] = events.Handle(callback, args) def remove_reader(self, fd): self.remove_reader_count[fd] += 1 @@ -235,7 +235,7 @@ class TestLoop(base_events.BaseEventLoop): handle._args, args) def add_writer(self, fd, callback, *args): - self.writers[fd] = events.make_handle(callback, args) + self.writers[fd] = events.Handle(callback, args) def remove_writer(self, fd): self.remove_writer_count[fd] += 1 diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 3ce2db8..ea79d33 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -64,7 +64,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): except ValueError as exc: raise RuntimeError(str(exc)) - handle = events.make_handle(callback, args) + handle = events.Handle(callback, args) self._signal_handlers[sig] = handle try: diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index c2988c0..4fb4b25 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -1660,12 +1660,12 @@ class HandleTests(unittest.TestCase): '<function HandleTests.test_handle.<locals>.callback')) self.assertTrue(r.endswith('())<cancelled>'), r) - def test_make_handle(self): + def test_handle(self): def callback(*args): return args h1 = asyncio.Handle(callback, ()) self.assertRaises( - AssertionError, asyncio.events.make_handle, h1, ()) + AssertionError, asyncio.Handle, h1, ()) @unittest.mock.patch('asyncio.events.logger') def test_callback_with_exception(self, log): |