8000 bpo-42392: Update code after merge review from 1st1 by uriyyo · Pull Request #23499 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42392: Update code after merge review from 1st1 #23499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add init method to _LoopBoundMixin to check that loop param wasn't used
  • Loading branch information
uriyyo committed Nov 25, 2020
commit 7a6156e281dad7b84548b62ad62f72b78c8c310b
33 changes: 10 additions & 23 deletions Lib/asyncio/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
from . import mixins


# Used as a sentinel for loop parameter
_marker = object()


def _verify_no_loop(obj, loop):
if loop is not _marker:
raise TypeError(
f'As of 3.10, the *loop* parameter was removed from '
f'{type(obj).__name__}() since it is no longer necessary'
)


class _ContextManagerMixin:
async def __aenter__(self):
await self.acquire()
Expand Down Expand Up @@ -85,8 +73,8 @@ class Lock(_ContextManagerMixin, mixins._LoopBoundMixin):

"""

def __init__(self, *, loop=_marker):
_verify_no_loop(self, loop)
def __init__(self, *, loop=mixins._marker):
super().__init__(loop=loop)
self._waiters = None
self._locked = False

Expand Down Expand Up @@ -175,8 +163,8 @@ class Event(mixins._LoopBoundMixin):
false.
"""

def __init__(self, loop=_marker):
_verify_no_loop(self, loop)
def __init__(self, *, loop=mixins._marker):
super().__init__(loop=loop)
self._waiters = collections.deque()
self._value = False

Expand Down Expand Up @@ -238,8 +226,8 @@ class Condition(_ContextManagerMixin, mixins._LoopBoundMixin):
A new Lock object is created and used as the underlying lock.
"""

def __init__(self, lock=None, *, loop=_marker):
_verify_no_loop(self, loop)
def __init__(self, lock=None, *, loop=mixins._marker):
super().__init__(loop=loop)
if lock is None:
lock = Lock()
elif lock._loop is not self._get_loop():
Expand Down Expand Up @@ -358,8 +346,8 @@ class Semaphore(_ContextManagerMixin, mixins._LoopBoundMixin):
ValueError is raised.
"""

def __init__(self, value=1, *, loop=_marker):
_verify_no_loop(self, loop)
def __init__(self, value=1, *, loop=mixins._marker):
super().__init__(loop=loop)
if value < 0:
raise ValueError("Semaphore initial value must be >= 0")
self._value = value
Expand Down Expand Up @@ -422,10 +410,9 @@ class BoundedSemaphore(Semaphore):
above the initial value.
"""

def __init__(self, value=1, *, loop=_marker):
_verify_no_loop(self, loop)
def __init__(self, value=1, *, loop=mixins._marker):
self._bound_value = value
super().__init__(value)
super().__init__(value, loop=loop)

def release(self):
if self._value >= self._bound_value:
Expand Down
10 changes: 10 additions & 0 deletions Lib/asyncio/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@

_global_lock = threading.Lock()

# Used as a sentinel for loop parameter
_marker = object()


class _LoopBoundMixin:
_loop = None

def __init__(self, *, loop=_marker):
if loop is not _marker:
raise TypeError(
f'As of 3.10, the *loop* parameter was removed from '
f'{type(self).__name__}() since it is no longer necessary'
)

def _get_loop(self):
loop = events._get_running_loop()

Expand Down
3 changes: 2 additions & 1 deletion Lib/asyncio/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Queue(mixins._LoopBoundMixin):
interrupted between calling qsize() and doing an operation on the Queue.
"""

def __init__(self, maxsize=0):
def __init__(self, maxsize=0, *, loop=mixins._marker):
super().__init__(loop=loop)
self._maxsize = maxsize

# Futures.
Expand Down
0