Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 1dd094a

Browse files
author
Anselm Kruis
committed
Merge branch master into master-slp
2 parents 19e9cef + 9a14214 commit 1dd094a

26 files changed

+1021
-558
lines changed

Lib/asyncio/locks.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ def __repr__(self):
411411
extra = '{},waiters:{}'.format(extra, len(self._waiters))
412412
return '<{} [{}]>'.format(res[1:-1], extra)
413413

414+
def _wake_up_next(self):
415+
while self._waiters:
416+
waiter = self._waiters.popleft()
417+
if not waiter.done():
418+
waiter.set_result(None)
419+
return
420+
414421
def locked(self):
415422
"""Returns True if semaphore can not be acquired immediately."""
416423
return self._value == 0
@@ -425,29 +432,27 @@ def acquire(self):
425432
called release() to make it larger than 0, and then return
426433
True.
427434
"""
428-
if not self._waiters and self._value > 0:
429-
self._value -= 1
430-
return True
431-
432-
fut = futures.Future(loop=self._loop)
433-
self._waiters.append(fut)
434-
try:
435-
yield from fut
436-
self._value -= 1
437-
return True
438-
finally:
439-
self._waiters.remove(fut)
435+
while self._value <= 0:
436+
fut = futures.Future(loop=self._loop)
437+
self._waiters.append(fut)
438+
try:
439+
yield from fut
440+
except:
441+
# See the similar code in Queue.get.
442+
fut.cancel()
443+
if self._value > 0 and not fut.cancelled():
444+
self._wake_up_next()
445+
raise
446+
self._value -= 1
447+
return True
440448

441449
def release(self):
442450
"""Release a semaphore, incrementing the internal counter by one.
443451
When it was zero on entry and another coroutine is waiting for it to
444452
become larger than zero again, wake up that coroutine.
445453
"""
446454
self._value += 1
447-
for waiter in self._waiters:
448-
if not waiter.done():
449-
waiter.set_result(True)
450-
break
455+
self._wake_up_next()
451456

452457

453458
class BoundedSemaphore(Semaphore):

Lib/asyncio/streams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def __init__(self, limit=_DEFAULT_LIMIT, loop=None):
324324
def __repr__(self):
325325
info = ['StreamReader']
326326
if self._buffer:
327-
info.append('%d bytes' % len(info))
327+
info.append('%d bytes' % len(self._buffer))
328328
if self._eof:
329329
info.append('eof')
330330
if self._limit != _DEFAULT_LIMIT:

Lib/collections/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,22 @@ def clear(self):
939939
class UserDict(MutableMapping):
940940

941941
# Start by filling-out the abstract methods
942-
def __init__(self, dict=None, **kwargs):
942+
def __init__(*args, **kwargs):
943+
if not args:
944+
raise TypeError("descriptor '__init__' of 'UserDict' object "
945+
"needs an argument")
946+
self, *args = args
947+
if len(args) > 1:
948+
raise TypeError('expected at most 1 arguments, got %d' % len(args))
949+
if args:
950+
dict = args[0]
951+
elif 'dict' in kwargs:
952+
dict = kwargs.pop('dict')
953+
import warnings
954+
warnings.warn("Passing 'dict' as keyword argument is deprecated",
955+
DeprecationWarning, stacklevel=2)
956+
else:
957+
dict = None
943958
self.data = {}
944959
if dict is not None:
945960
self.update(dict)

Lib/pickle.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,14 @@ def load_binunicode8(self):
12391239
self.append(str(self.read(len), 'utf-8', 'surrogatepass'))
12401240
dispatch[BINUNICODE8[0]] = load_binunicode8
12411241

1242+
def load_binbytes8(self):
1243+
len, = unpack('<Q', self.read(8))
1244+
if len > maxsize:
1245+
raise UnpicklingError("BINBYTES8 exceeds system's maximum size "
1246+
"of %d bytes" % maxsize)
1247+
self.append(self.read(len))
1248+
dispatch[BINBYTES8[0]] = load_binbytes8
1249+
12421250
def load_short_binstring(self):
12431251
len = self.read(1)[0]
12441252
data = self.read(len)

Lib/string.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def format(*args, **kwargs):
183183

184184
def vformat(self, format_string, args, kwargs):
185185
used_args = set()
186-
result = self._vformat(format_string, args, kwargs, used_args, 2)
186+
result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
187187
self.check_unused_args(used_args, args, kwargs)
188188
return result
189189

@@ -230,14 +230,15 @@ def _vformat(self, format_string, args, kwargs, used_args, recursion_depth,
230230
obj = self.convert_field(obj, conversion)
231231

232232
# expand the format spec, if needed
233-
format_spec = self._vformat(format_spec, args, kwargs,
234-
used_args, recursion_depth-1,
235-
auto_arg_index=auto_arg_index)
233+
format_spec, auto_arg_index = self._vformat(
234+
format_spec, args, kwargs,
235+
used_args, recursion_depth-1,
236+
auto_arg_index=auto_arg_index)
236237

237238
# format the object and append to the result
238239
result.append(self.format_field(obj, format_spec))
239240

240-
return ''.join(result)
241+
return ''.join(result), auto_arg_index
241242

242243

243244
def get_value(self, key, args, kwargs):

Lib/test/libregrtest/cmdline.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ def _parse_args(args, **kwargs):
295295
parser.error("-T and -j don't go together!")
296296
if ns.use_mp and ns.findleaks:
297297
parser.error("-l and -j don't go together!")
298-
if ns.use_mp and ns.memlimit:
299-
parser.error("-M and -j don't go together!")
300298
if ns.failfast and not (ns.verbose or ns.verbose3):
301299
parser.error("-G/--failfast needs either -v or -W")
302300

0 commit comments

Comments
 (0)