8000 Issue #112: Inline make_handle() into Handle constructor · python/asyncio@5f11d83 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit 5f11d83

Browse files
committed
Issue #112: Inline make_handle() into Handle constructor
1 parent fdd
8000
fe52 commit 5f11d83

File tree

6 files changed

+9
-14
lines changed

6 files changed

+9
-14
lines changed

asyncio/base_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def call_soon(self, callback, *args):
240240
Any positional arguments after the callback will be passed to
241241
the callback when it is called.
242242
"""
243-
handle = events.make_handle(callback, args)
243+
handle = events.Handle(callback, args)
244244
self._ready.append(handle)
245245
return handle
246246

asyncio/events.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Handle:
2020
"""Object returned by callback registration methods."""
2121

2222
def __init__(self, callback, args):
23+
assert not isinstance(callback, Handle), 'A Handle is not a callback'
2324
self._callback = callback
2425
self._args = args
2526
self._cancelled = False
@@ -42,12 +43,6 @@ def _run(self):
4243
self = None # Needed to break cycles when an exception occurs.
4344

4445

45-
def make_handle(callback, args):
46-
# TODO: Inline this? Or make it a private EventLoop method?
47-
assert not isinstance(callback, Handle), 'A Handle is not a callback'
48-
return Handle(callback, args)
49-
50-
5146
class TimerHandle(Handle):
5247
"""Object returned by timed callback registration methods."""
5348

asyncio/selector_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _accept_connection(self, protocol_factory, sock,
132132

133133
def add_reader(self, fd, callback, *args):
134134
"""Add a reader callback."""
135-
handle = events.make_handle(callback, args)
135+
handle = events.Handle(callback, args)
136136
try:
137137
key = self._selector.get_key(fd)
138138
except KeyError:
@@ -167,7 +167,7 @@ def remove_reader(self, fd):
167167

168168
def add_writer(self, fd, callback, *args):
169169
"""Add a writer callback.."""
170-
handle = events.make_handle(callback, args)
170+
handle = events.Handle(callback, args)
171171
try:
172172
key = self._selector.get_key(fd)
173173
except KeyError:

asyncio/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def close(self):
216216
raise AssertionError("Time generator is not finished")
217217

218218
def add_reader(self, fd, callback, *args):
219-
self.readers[fd] = events.make_handle(callback, args)
219+
self.readers[fd] = events.Handle(callback, args)
220220

221221
def remove_reader(self, fd):
222222
self.remove_reader_count[fd] += 1
@@ -235,7 +235,7 @@ def assert_reader(self, fd, callback, *args):
235235
handle._args, args)
236236

237237
def add_writer(self, fd, callback, *args):
238-
self.writers[fd] = events.make_handle(callback, args)
238+
self.writers[fd] = events.Handle(callback, args)
239239

240240
def remove_writer(self, fd):
241241
self.remove_writer_count[fd] += 1

asyncio/unix_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def add_signal_handler(self, sig, callback, *args):
6464
except ValueError as exc:
6565
raise RuntimeError(str(exc))
6666

67-
handle = events.make_handle(callback, args)
67+
handle = events.Handle(callback, args)
6868
self._signal_handlers[sig] = handle
6969

7070
try:

tests/test_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,12 +1660,12 @@ def callback(*args):
16601660
'<function HandleTests.test_handle.<locals>.callback'))
16611661
self.assertTrue(r.endswith('())<cancelled>'), r)
16621662

1663-
def test_make_handle(self):
1663+
def test_handle(self):
16641664
def callback(*args):
16651665
return args
16661666
h1 = asyncio.Handle(callback, ())
16671667
self.assertRaises(
1668-
AssertionError, asyncio.events.make_handle, h1, ())
1668+
AssertionError, asyncio.Handle, h1, ())
16691669

16701670
@unittest.mock.patch('asyncio.events.logger')
16711671
def test_callback_with_exception(self, log):

0 commit comments

Comments
 (0)
0