Skip to content

Commit 4685e5b

Browse files
committed
📝 Add what’s new in Python 3.15
* Add lacy imports * Add frozendict * Add unpacking in comprehensions
1 parent 0983f9c commit 4685e5b

6 files changed

Lines changed: 97 additions & 0 deletions

File tree

‎CHANGELOG.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ emergencies when we need to start branches for older versions.
1919
Added
2020
~~~~~
2121

22+
* 📝 Add what’s new in Python 3.15
23+
24+
* Add lacy imports
25+
* Add frozendict
26+
* Add unpacking in comprehensions
27+
2228
* 📝 Add timezones
2329
* 📝 Add pytest-leak-finder
2430

‎docs/control-flow/loops.rst‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ Das allgemeine Format für Dict Comprehensions ist:
180180

181181
:samp:`{NEW_DICT} = \{{KEY}: {VALUE} for {MEMBER} in {ITERABLE}\}`
182182

183+
.. _unpacking_in_comprehensions:
184+
185+
Unpack
186+
~~~~~~
187+
188+
.. versionadded:: 3.15
189+
190+
In line with :pep:`798`, :doc:`../types/sequences-sets/lists`,
191+
:doc:`../types/sequences-sets/sets` and :doc:`../types/dicts` now support
192+
comprehensions using ``*`` and ``**``:
193+
194+
.. code-block:: pycon
195+
196+
>>> nested_list = [[0, 1], [2, 3], [4, 5]]
197+
>>> [*l for l in nested_list]
198+
[0, 1, 2, 3, 4, 5]
199+
>>>
200+
>>> nested_dict = [{0: "a"}, {1: "b"}, {2: "c"}]
201+
>>> {**d for d in nested_dict}
202+
{0: 'a', 1: 'b', 2: 'c'}
203+
183204
Change a ``Collection``
184205
~~~~~~~~~~~~~~~~~~~~~~~
185206

‎docs/modules/index.rst‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ provided via special modules that you can load as needed.
4848
.. seealso::
4949
* :ref:`python3:py-modindex`
5050

51+
.. _explicit-lazy-imports:
52+
53+
.. versionadded:: 3.15
54+
55+
Python 3.15 introduces explicit lazy imports via :pep:`810`: if an ``import``
56+
statement is prefixed with the keyword ``lazy``, the module is not loaded
57+
immediately; instead, a proxy object is created. The actual module is loaded
58+
the first time it is used:
59+
60+
.. code-block:: pycon
61+
62+
>>> import sys
63+
>>> lazy import json
64+
>>> lazy from pathlib import Path
65+
>>> "json" in sys.modules
66+
False
67+
>>> with Path.open("books.json") as f:
68+
... data = json.load(f)
69+
...
70+
>>> "json" in sys.modules
71+
True
72+
73+
.. seealso::
74+
* :ref:`lazy-imports`
75+
5176
Creating modules
5277
----------------
5378

‎docs/types/dicts.rst‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,46 @@ keys of a dict, for example:
109109
>>> collections.Counter(titles)
110110
Counter({'Lists': 2, 'Data types': 1, 'Sets': 1})
111111
112+
.. _frozendict:
113+
114+
``frozendict``
115+
--------------
116+
117+
.. versionadded:: 3.15
118+
119+
:pep:`814` introduces :class:`python3:frozendict`, an :term:`immutable`
120+
dictionary:
121+
122+
.. code-block:: pycon
123+
124+
>>> titles = frozendict({7.0: "Data Types", 7.1: "Lists", 7.2: "Tuples"})
125+
>>> titles
126+
frozendict({7.0: 'Data Types', 7.1: 'Lists', 7.2: 'Tuples'})
127+
>>> titles[7.3] = "Sets"
128+
Traceback (most recent call last):
129+
File "<python-input-16>", line 1, in <module>
130+
titles[7.3] = "Sets"
131+
~~~~~~^^^^^
132+
TypeError: 'frozendict' object does not support item assignment
133+
134+
Immutable mappings are hashable, which means they can be used as keys in
135+
dictionaries, as elements in :doc:`sets <sequences-sets/sets>`, or accepted
136+
as arguments by functions :doc:`decorated <../functions/decorators>` with
137+
:func:`@functools.lru_cache`:
138+
139+
.. code-block:: pycon
140+
141+
>>> hash(titles)
142+
3827265406416199624
143+
144+
The merge operator (``|``) can be used to merge two ``frozendict`` objects or
145+
a ``frozendict`` object with a ``dict`` object, for example:
146+
147+
.. code-block:: pycon
148+
149+
>>> titles | new_titles
150+
frozendict({7.0: 'Data types', 7.1: 'Lists', 7.2: 'Tuples', 7.3: 'Sets'})
151+
112152
Extensions
113153
----------
114154

‎docs/types/index.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ appropriate special method attributes.
4040
Python has several built-in data types, from scalars like numbers and boolean
4141
values to more complex structures like lists, dictionaries and files.
4242

43+
.. seealso::
44+
* :doc:`python3:builtins/stdtypes`
45+
4346
.. toctree::
4447
:titlesonly:
4548
:hidden:

‎docs/types/strings/encodings.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ defines several different encodings from a single character set. UTF-8 is an
111111
encoding scheme for representing Unicode characters as binary data with one or
112112
more bytes per character.
113113

114+
.. _default-encoding:
115+
114116
.. versionadded:: 3.15
115117
Python 3.15 uses UTF-8 as the default encoding, regardless of the system
116118
environment. This means that I/O operations without explicit encoding, for

0 commit comments

Comments
 (0)