Skip to content

Commit

Permalink
Merge branch 'main' into rl_hook_types
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland authored Apr 15, 2024
2 parents 9322a84 + a9107fe commit 75dc1b3
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 108 deletions.
170 changes: 85 additions & 85 deletions Doc/library/dataclasses.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ gc
--

* The cyclic garbage collector is now incremental, which changes the meanings
of the results of :meth:`gc.get_threshold` and :meth:`gc.get_threshold` as
of the results of :meth:`gc.get_threshold` and :meth:`gc.set_threshold` as
well as :meth:`gc.get_count` and :meth:`gc.get_stats`.
* :meth:`gc.get_threshold` returns a three-tuple for backwards compatibility,
the first value is the threshold for young collections, as before, the second
Expand Down
2 changes: 0 additions & 2 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def join(path, *paths):
seps = '\\/'
colon_seps = ':\\/'
try:
if not paths:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
result_drive, result_root, result_path = splitroot(path)
for p in paths:
p_drive, p_root, p_path = splitroot(p)
Expand Down
6 changes: 2 additions & 4 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ def join(a, *p):
sep = _get_sep(a)
path = a
try:
if not p:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
for b in p:
b = os.fspath(b)
if b.startswith(sep):
if b.startswith(sep) or not path:
path = b
elif not path or path.endswith(sep):
elif path.endswith(sep):
path += b
else:
path += sep + b
Expand Down
12 changes: 11 additions & 1 deletion Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
from test.support.script_helper import (
assert_python_ok, assert_python_failure, run_python_until_end)
from test.support import (
import_helper, is_apple, os_helper, skip_if_sanitizer, threading_helper, warnings_helper
import_helper, is_apple, os_helper, skip_if_sanitizer, threading_helper, warnings_helper,
skip_on_s390x
)
from test.support.os_helper import FakePath

Expand Down Expand Up @@ -1700,6 +1701,9 @@ class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
@skip_if_sanitizer(memory=True, address=True, thread=True,
reason="sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
@skip_on_s390x
def test_constructor(self):
BufferedReaderTest.test_constructor(self)
# The allocation can succeed on 32-bit builds, e.g. with more
Expand Down Expand Up @@ -2068,6 +2072,9 @@ class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
@skip_if_sanitizer(memory=True, address=True, thread=True,
reason="sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
@skip_on_s390x
def test_constructor(self):
BufferedWriterTest.test_constructor(self)
# The allocation can succeed on 32-bit builds, e.g. with more
Expand Down Expand Up @@ -2590,6 +2597,9 @@ class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
@skip_if_sanitizer(memory=True, address=True, thread=True,
reason="sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
@skip_on_s390x
def test_constructor(self):
BufferedRandomTest.test_constructor(self)
# The allocation can succeed on 32-bit builds, e.g. with more
Expand Down
27 changes: 24 additions & 3 deletions Lib/test/test_json/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,34 @@
class TestDecode:
def test_decimal(self):
rval = self.loads('1.1', parse_float=decimal.Decimal)
self.assertTrue(isinstance(rval, decimal.Decimal))
self.assertIsInstance(rval, decimal.Decimal)
self.assertEqual(rval, decimal.Decimal('1.1'))

def test_float(self):
rval = self.loads('1', parse_int=float)
self.assertTrue(isinstance(rval, float))
self.assertIsInstance(rval, float)
self.assertEqual(rval, 1.0)

def test_bytes(self):
self.assertEqual(self.loads(b"1"), 1)

def test_parse_constant(self):
for constant, expected in [
("Infinity", "INFINITY"),
("-Infinity", "-INFINITY"),
("NaN", "NAN"),
]:
self.assertEqual(
self.loads(constant, parse_constant=str.upper), expected
)

def test_constant_invalid_case(self):
for constant in [
"nan", "NAN", "naN", "infinity", "INFINITY", "inFiniTy"
]:
with self.assertRaises(self.JSONDecodeError):
self.loads(constant)

def test_empty_objects(self):
self.assertEqual(self.loads('{}'), {})
self.assertEqual(self.loads('[]'), [])
Expand Down Expand Up @@ -88,7 +108,8 @@ def test_string_with_utf8_bom(self):
self.json.load(StringIO(bom_json))
self.assertIn('BOM', str(cm.exception))
# make sure that the BOM is not detected in the middle of a string
bom_in_str = '"{}"'.format(''.encode('utf-8-sig').decode('utf-8'))
bom = ''.encode('utf-8-sig').decode('utf-8')
bom_in_str = f'"{bom}"'
self.assertEqual(self.loads(bom_in_str), '\ufeff')
self.assertEqual(self.json.load(StringIO(bom_in_str)), '\ufeff')

Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_json/test_encode_basestring_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def test_encode_basestring_ascii(self):
for input_string, expect in CASES:
result = self.json.encoder.encode_basestring_ascii(input_string)
self.assertEqual(result, expect,
'{0!r} != {1!r} for {2}({3!r})'.format(
result, expect, fname, input_string))
f'{result!r} != {expect!r} for {fname}({input_string!r})')

def test_ordered_dict(self):
# See issue 6105
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_json/test_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_failures(self):
except self.JSONDecodeError:
pass
else:
self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))
self.fail(f"Expected failure for fail{idx}.json: {doc!r}")

def test_non_string_keys_dict(self):
data = {'a' : 1, (1, 2) : 2}
Expand Down
13 changes: 9 additions & 4 deletions Lib/test/test_json/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ def test_encoding4(self):
def test_encoding5(self):
u = '\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
j = self.dumps(u, ensure_ascii=False)
self.assertEqual(j, '"{0}"'.format(u))
self.assertEqual(j, f'"{u}"')

def test_encoding6(self):
u = '\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
j = self.dumps([u], ensure_ascii=False)
self.assertEqual(j, '["{0}"]'.format(u))
self.assertEqual(j, f'["{u}"]')

def test_encoding7(self):
u = '\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
j = self.dumps(u + "\n", ensure_ascii=False)
self.assertEqual(j, f'"{u}\\n"')

def test_big_unicode_encode(self):
u = '\U0001d120'
Expand All @@ -34,13 +39,13 @@ def test_big_unicode_encode(self):

def test_big_unicode_decode(self):
u = 'z\U0001d120x'
self.assertEqual(self.loads('"' + u + '"'), u)
self.assertEqual(self.loads(f'"{u}"'), u)
self.assertEqual(self.loads('"z\\ud834\\udd20x"'), u)

def test_unicode_decode(self):
for i in range(0, 0xd7ff):
u = chr(i)
s = '"\\u{0:04x}"'.format(i)
s = f'"\\u{i:04x}"'
self.assertEqual(self.loads(s), u)

def test_unicode_preservation(self):
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_join(self):
self.assertEqual(fn(b"/foo", b"bar", b"baz"), b"/foo/bar/baz")
self.assertEqual(fn(b"/foo/", b"bar/", b"baz/"), b"/foo/bar/baz/")

self.assertEqual(fn("a", ""), "a/")
self.assertEqual(fn("a", "", ""), "a/")
self.assertEqual(fn("a", "b"), "a/b")
self.assertEqual(fn("a", "b/"), "a/b/")
self.assertEqual(fn("a/", "b"), "a/b")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speedup :func:`os.path.join`.
7 changes: 2 additions & 5 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,7 @@ static int
delitemif_lock_held(PyObject *op, PyObject *key,
int (*predicate)(PyObject *value))
{
Py_ssize_t hashpos, ix;
Py_ssize_t ix;
PyDictObject *mp;
Py_hash_t hash;
PyObject *old_value;
Expand Down Expand Up @@ -2632,14 +2632,11 @@ delitemif_lock_held(PyObject *op, PyObject *key,
if (res == -1)
return -1;

hashpos = lookdict_index(mp->ma_keys, hash, ix);
assert(hashpos >= 0);

if (res > 0) {
PyInterpreterState *interp = _PyInterpreterState_GET();
uint64_t new_version = _PyDict_NotifyEvent(
interp, PyDict_EVENT_DELETED, mp, key, NULL);
return delitem_common(mp, hashpos, ix, old_value, new_version);
return delitem_common(mp, hash, ix, old_value, new_version);
} else {
return 0;
}
Expand Down

0 comments on commit 75dc1b3

Please sign in to comment.