Skip to content

Commit d3cbe13

Browse files
Merge branch 'main' into _locale-_getdefaultlocale-leak
2 parents ed49459 + 06b0920 commit d3cbe13

File tree

18 files changed

+97
-12
lines changed

18 files changed

+97
-12
lines changed

Doc/c-api/dict.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Dictionary objects
8282
8383
Return a new dictionary that contains the same key-value pairs as *p*.
8484
85+
.. versionchanged:: next
86+
If *p* is a subclass of :class:`frozendict`, the result will be a
87+
:class:`frozendict` instance instead of a :class:`dict` instance.
8588
8689
.. c:function:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
8790

Doc/library/stdtypes.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,19 @@ expression support in the :mod:`re` module).
25042504
done using the specified *fillchar* (default is an ASCII space). The
25052505
original string is returned if *width* is less than or equal to ``len(s)``.
25062506

2507+
For example:
2508+
2509+
.. doctest::
2510+
2511+
>>> 'Python'.rjust(10)
2512+
' Python'
2513+
>>> 'Python'.rjust(10, '.')
2514+
'....Python'
2515+
>>> 'Monty Python'.rjust(10, '.')
2516+
'Monty Python'
2517+
2518+
See also :meth:`ljust` and :meth:`zfill`.
2519+
25072520

25082521
.. method:: str.rpartition(sep, /)
25092522

@@ -2828,13 +2841,17 @@ expression support in the :mod:`re` module).
28282841
than before. The original string is returned if *width* is less than
28292842
or equal to ``len(s)``.
28302843

2831-
For example::
2844+
For example:
2845+
2846+
.. doctest::
28322847

28332848
>>> "42".zfill(5)
28342849
'00042'
28352850
>>> "-42".zfill(5)
28362851
'-0042'
28372852

2853+
See also :meth:`rjust`.
2854+
28382855

28392856
.. index::
28402857
single: ! formatted string literal

Doc/library/typing.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,8 +3353,8 @@ Introspection helpers
33533353

33543354
.. function:: get_type_hints(obj, globalns=None, localns=None, include_extras=False)
33553355

3356-
Return a dictionary containing type hints for a function, method, module
3357-
or class object.
3356+
Return a dictionary containing type hints for a function, method, module,
3357+
class object, or other callable object.
33583358

33593359
This is often the same as ``obj.__annotations__``, but this function makes
33603360
the following changes to the annotations dictionary:
@@ -3395,6 +3395,13 @@ Introspection helpers
33953395
:ref:`type aliases <type-aliases>` that include forward references,
33963396
or with names imported under :data:`if TYPE_CHECKING <TYPE_CHECKING>`.
33973397

3398+
.. note::
3399+
3400+
Calling :func:`get_type_hints` on an instance is not supported.
3401+
To retrieve annotations for an instance, call
3402+
:func:`get_type_hints` on the instance's class instead
3403+
(for example, ``get_type_hints(type(obj))``).
3404+
33983405
.. versionchanged:: 3.9
33993406
Added ``include_extras`` parameter as part of :pep:`593`.
34003407
See the documentation on :data:`Annotated` for more information.
@@ -3404,6 +3411,11 @@ Introspection helpers
34043411
if a default value equal to ``None`` was set.
34053412
Now the annotation is returned unchanged.
34063413

3414+
.. versionchanged:: 3.14
3415+
Calling :func:`get_type_hints` on instances is no longer supported.
3416+
Some instances were accepted in earlier versions as an undocumented
3417+
implementation detail.
3418+
34073419
.. function:: get_origin(tp)
34083420

34093421
Get the unsubscripted version of a type: for a typing object of the form

Lib/test/test_decimal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,15 +3963,21 @@ def test_flag_comparisons(self):
39633963
d.update(c.flags)
39643964
self.assertEqual(d, c.flags)
39653965
self.assertEqual(c.flags, d)
3966+
self.assertEqual(frozendict(d), c.flags)
3967+
self.assertEqual(c.flags, frozendict(d))
39663968

39673969
d[Inexact] = True
39683970
self.assertNotEqual(d, c.flags)
39693971
self.assertNotEqual(c.flags, d)
3972+
self.assertNotEqual(frozendict(d), c.flags)
3973+
self.assertNotEqual(c.flags, frozendict(d))
39703974

39713975
# Invalid SignalDict
39723976
d = {Inexact:False}
39733977
self.assertNotEqual(d, c.flags)
39743978
self.assertNotEqual(c.flags, d)
3979+
self.assertNotEqual(frozendict(d), c.flags)
3980+
self.assertNotEqual(c.flags, frozendict(d))
39753981

39763982
d = ["xyz"]
39773983
self.assertNotEqual(d, c.flags)

Lib/test/test_source_encoding.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ def test_issue7820(self):
6565
# two bytes in common with the UTF-8 BOM
6666
self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20')
6767

68+
def test_truncated_utf8_at_eof(self):
69+
# Regression test for https://issues.oss-fuzz.com/issues/451112368
70+
# Truncated multi-byte UTF-8 sequences at end of input caused an
71+
# out-of-bounds read in Parser/tokenizer/helpers.c:valid_utf8().
72+
truncated = [
73+
b'\xc2', # 2-byte lead, missing 1 continuation
74+
b'\xdf', # 2-byte lead, missing 1 continuation
75+
b'\xe0', # 3-byte lead, missing 2 continuations
76+
b'\xe0\xa0', # 3-byte lead, missing 1 continuation
77+
b'\xf0\x90', # 4-byte lead, missing 2 continuations
78+
b'\xf0\x90\x80', # 4-byte lead, missing 1 continuation
79+
b'\xf3', # 4-byte lead, missing 3 (the oss-fuzz reproducer)
80+
]
81+
for seq in truncated:
82+
with self.subTest(seq=seq):
83+
self.assertRaises(SyntaxError, compile, seq, '<test>', 'exec')
84+
6885
@support.requires_subprocess()
6986
def test_20731(self):
7087
sub = subprocess.Popen([sys.executable,

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,11 @@ def test_blob_get_slice(self):
13791379
def test_blob_get_empty_slice(self):
13801380
self.assertEqual(self.blob[5:5], b"")
13811381

1382+
def test_blob_get_empty_slice_oob_indices(self):
1383+
self.cx.execute("insert into test(b) values (?)", (b"abc",))
1384+
with self.cx.blobopen("test", "b", 2) as blob:
1385+
self.assertEqual(blob[5:-5], b"")
1386+
13821387
def test_blob_get_slice_negative_index(self):
13831388
self.assertEqual(self.blob[5:-5], self.data[5:-5])
13841389

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix heap buffer overflow in the parser found by OSS-Fuzz.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix assertion failure in :mod:`sqlite3` blob subscript when slicing with
2+
indices that result in an empty slice.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash in ``_remote_debugging`` that caused ``test_external_inspection`` to intermittently fail. Patch by Taegyun Kim.

Modules/_decimal/_decimal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ dict_as_flags(decimal_state *state, PyObject *val)
552552
uint32_t flags = 0;
553553
int x;
554554

555-
if (!PyDict_Check(val)) {
555+
if (!PyAnyDict_Check(val)) {
556556
PyErr_SetString(PyExc_TypeError,
557557
"argument must be a signal dict");
558558
return DEC_INVALID_SIGNALS;
@@ -802,7 +802,7 @@ signaldict_richcompare(PyObject *v, PyObject *w, int op)
802802
if (PyDecSignalDict_Check(state, w)) {
803803
res = (SdFlags(v)==SdFlags(w)) ^ (op==Py_NE) ? Py_True : Py_False;
804804
}
805-
else if (PyDict_Check(w)) {
805+
else if (PyAnyDict_Check(w)) {
806806
uint32_t flags = dict_as_flags(state, w);
807807
if (flags & DEC_ERRORS) {
808808
if (flags & DEC_INVALID_SIGNALS) {

0 commit comments

Comments
 (0)