Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions Doc/c-api/dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Dictionary objects

Return a new dictionary that contains the same key-value pairs as *p*.

.. versionchanged:: next
If *p* is a subclass of :class:`frozendict`, the result will be a
:class:`frozendict` instance instead of a :class:`dict` instance.

.. c:function:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)

Expand Down
19 changes: 18 additions & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,19 @@ expression support in the :mod:`re` module).
done using the specified *fillchar* (default is an ASCII space). The
original string is returned if *width* is less than or equal to ``len(s)``.

For example:

.. doctest::

>>> 'Python'.rjust(10)
' Python'
>>> 'Python'.rjust(10, '.')
'....Python'
>>> 'Monty Python'.rjust(10, '.')
'Monty Python'

See also :meth:`ljust` and :meth:`zfill`.


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

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

For example::
For example:

.. doctest::

>>> "42".zfill(5)
'00042'
>>> "-42".zfill(5)
'-0042'

See also :meth:`rjust`.


.. index::
single: ! formatted string literal
Expand Down
16 changes: 14 additions & 2 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3353,8 +3353,8 @@ Introspection helpers

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

Return a dictionary containing type hints for a function, method, module
or class object.
Return a dictionary containing type hints for a function, method, module,
class object, or other callable object.

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

.. note::

Calling :func:`get_type_hints` on an instance is not supported.
To retrieve annotations for an instance, call
:func:`get_type_hints` on the instance's class instead
(for example, ``get_type_hints(type(obj))``).

.. versionchanged:: 3.9
Added ``include_extras`` parameter as part of :pep:`593`.
See the documentation on :data:`Annotated` for more information.
Expand All @@ -3404,6 +3411,11 @@ Introspection helpers
if a default value equal to ``None`` was set.
Now the annotation is returned unchanged.

.. versionchanged:: 3.14
Calling :func:`get_type_hints` on instances is no longer supported.
Some instances were accepted in earlier versions as an undocumented
implementation detail.

.. function:: get_origin(tp)

Get the unsubscripted version of a type: for a typing object of the form
Expand Down
24 changes: 24 additions & 0 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import sys
import unicodedata
import unittest
import weakref
from test.support import (
gc_collect,
open_urlresource,
requires_resource,
script_helper,
Expand Down Expand Up @@ -1338,6 +1340,28 @@ def run_grapheme_break_tests(self, testdata):
self.assertEqual([x.start for x in result], breaks[i:-1], comment)
self.assertEqual([x.end for x in result], breaks[i+1:], comment)

def test_reference_loops(self):
# Test that reference loops involving GraphemeBreakIterator or
# Segment can be broken by the garbage collector.
class S(str):
pass

s = S('abc')
s.ref = unicodedata.iter_graphemes(s)
wr = weakref.ref(s)
del s
self.assertIsNotNone(wr())
gc_collect()
self.assertIsNone(wr())

s = S('abc')
s.ref = next(unicodedata.iter_graphemes(s))
wr = weakref.ref(s)
del s
self.assertIsNotNone(wr())
gc_collect()
self.assertIsNone(wr())


if __name__ == "__main__":
unittest.main()
20 changes: 2 additions & 18 deletions Modules/unicodedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1925,13 +1925,6 @@ Segment_traverse(PyObject *self, visitproc visit, void *arg)
return 0;
}

static int
Segment_clear(PyObject *self)
{
Py_CLEAR(((SegmentObject *)self)->string);
return 0;
}

static PyObject *
Segment_str(PyObject *self)
{
Expand All @@ -1947,17 +1940,16 @@ Segment_repr(PyObject *self)
}

static PyMemberDef Segment_members[] = {
{"start", Py_T_PYSSIZET, offsetof(SegmentObject, start), 0,
{"start", Py_T_PYSSIZET, offsetof(SegmentObject, start), Py_READONLY,
PyDoc_STR("grapheme start")},
{"end", Py_T_PYSSIZET, offsetof(SegmentObject, end), 0,
{"end", Py_T_PYSSIZET, offsetof(SegmentObject, end), Py_READONLY,
PyDoc_STR("grapheme end")},
{NULL} /* Sentinel */
};

static PyType_Slot Segment_slots[] = {
{Py_tp_dealloc, Segment_dealloc},
{Py_tp_traverse, Segment_traverse},
{Py_tp_clear, Segment_clear},
{Py_tp_str, Segment_str},
{Py_tp_repr, Segment_repr},
{Py_tp_members, Segment_members},
Expand Down Expand Up @@ -2001,13 +1993,6 @@ GBI_traverse(PyObject *self, visitproc visit, void *arg)
return 0;
}

static int
GBI_clear(PyObject *self)
{
Py_CLEAR(((GraphemeBreakIterator *)self)->iter.str);
return 0;
}

static PyObject *
GBI_iternext(PyObject *self)
{
Expand Down Expand Up @@ -2038,7 +2023,6 @@ static PyType_Slot GraphemeBreakIterator_slots[] = {
{Py_tp_iter, PyObject_SelfIter},
{Py_tp_iternext, GBI_iternext},
{Py_tp_traverse, GBI_traverse},
{Py_tp_clear, GBI_clear},
{0, 0},
};

Expand Down
Loading