@@ -242,6 +242,7 @@ Windows support contributed by Dino Viehland and Anthony Shaw.)
242
242
243
243
.. _`PyPy project` : https://pypy.org/
244
244
245
+
245
246
.. _whatsnew313-improved-error-messages :
246
247
247
248
Improved error messages
@@ -492,138 +493,123 @@ Incremental garbage collection
492
493
The cycle garbage collector is now incremental.
493
494
This means that maximum pause times are reduced
494
495
by an order of magnitude or more for larger heaps.
496
+ (Contributed by Mark Shannon in :gh: `108362 `.)
495
497
496
498
497
499
Other Language Changes
498
500
======================
499
501
500
- * Classes have a new :attr: `~class.__static_attributes__ ` attribute, populated by the compiler,
501
- with a tuple of names of attributes of this class which are assigned
502
- through ``self.X `` from any function in its body. (Contributed by Irit Katriel
503
- in :gh: `115775 `.)
502
+ * The compiler now strips common common leading whitespace
503
+ from every line in a docstring.
504
+ This reduces the size of the :term: `bytecode cache <bytecode> `
505
+ (such as ``.pyc `` files), with reductions in file size of around 5%,
506
+ for example in :mod: `!sqlalchemy.orm.session ` from SQLAlchemy 2.0.
507
+ This change affects tools that use docstrings, such as :mod: `doctest `.
508
+
509
+ .. doctest ::
510
+
511
+ >>> def spam ():
512
+ ... """
513
+ ... This is a docstring with
514
+ ... leading whitespace.
515
+ ...
516
+ ... It even has multiple paragraphs!
517
+ ... """
518
+ ...
519
+ >>> spam.__doc__
520
+ '\nThis is a docstring with\n leading whitespace.\n\nIt even has multiple paragraphs!\n'
504
521
505
- * The :func: `exec ` and :func: `eval ` built-ins now accept their ``globals ``
506
- and ``locals `` namespace arguments as keywords.
507
- (Contributed by Raphael Gaschignard in :gh: `105879 `)
522
+ (Contributed by Inada Naoki in :gh: `81283 `.)
508
523
509
- * Allow the *count * argument of :meth: `str.replace ` to be a keyword.
510
- (Contributed by Hugo van Kemenade in :gh: `106487 `.)
524
+ * :ref: `Annotation scopes <annotation-scopes >` within class scopes
525
+ can now contain lambdas and comprehensions.
526
+ Comprehensions that are located within class scopes
527
+ are not inlined into their parent scope.
511
528
512
- * Compiler now strip indents from docstrings.
513
- This will reduce the size of :term: `bytecode cache <bytecode> ` (e.g. ``.pyc `` file).
514
- For example, cache file size for ``sqlalchemy.orm.session `` in SQLAlchemy 2.0
515
- is reduced by about 5%.
516
- This change will affect tools using docstrings, like :mod: `doctest `.
517
- (Contributed by Inada Naoki in :gh: `81283 `.)
529
+ .. code-block :: python
518
530
519
- * The :func: `compile ` built-in can now accept a new flag,
520
- ``ast.PyCF_OPTIMIZED_AST ``, which is similar to ``ast.PyCF_ONLY_AST ``
521
- except that the returned ``AST `` is optimized according to the value
522
- of the ``optimize `` argument.
523
- (Contributed by Irit Katriel in :gh: `108113 `).
531
+ class C[T]:
532
+ type Alias = lambda : T
524
533
525
- * :mod: `multiprocessing `, :mod: `concurrent.futures `, :mod: `compileall `:
526
- Replace :func: `os.cpu_count ` with :func: `os.process_cpu_count ` to select the
527
- default number of worker threads and processes. Get the CPU affinity
528
- if supported.
529
- (Contributed by Victor Stinner in :gh: `109649 `.)
534
+ (Contributed by Jelle Zijlstra in :gh: `109118 ` and :gh: `118160 `.)
530
535
531
- * :func: `os.path.realpath ` now resolves MS-DOS style file names even if
532
- the file is not accessible.
533
- (Contributed by Moonsik Park in :gh: `82367 `.)
536
+ * :ref: `Future statements <future >` are no longer triggered by
537
+ relative imports of the :mod: `__future__ ` module,
538
+ meaning that statements of the form ``from .__future__ import ... ``
539
+ are now simply standard relative imports, with no special features activated.
540
+ (Contributed by Jeremiah Gabriel Pascual in :gh: `118216 `.)
534
541
535
- * Fixed a bug where a :keyword: `global ` declaration in an :keyword: `except ` block
536
- is rejected when the global is used in the :keyword: `else ` block.
542
+ * :keyword: `global ` declarations are now permitted in :keyword: `except ` blocks
543
+ when that global is used in the :keyword: `else ` block.
544
+ Previously this raised an erroneous :exc: `SyntaxError `.
537
545
(Contributed by Irit Katriel in :gh: `111123 `.)
538
546
539
- * Many functions now emit a warning if a boolean value is passed as
540
- a file descriptor argument.
541
- This can help catch some errors earlier.
542
- (Contributed by Serhiy Storchaka in :gh: `82626 `.)
543
-
544
- * Added a new environment variable :envvar: `PYTHON_FROZEN_MODULES `. It
545
- determines whether or not frozen modules are ignored by the import machinery,
546
- equivalent of the :option: `-X frozen_modules <-X> ` command-line option.
547
+ * Add :envvar: `PYTHON_FROZEN_MODULES `, a new environment variable that
548
+ determines whether frozen modules are ignored by the import machinery,
549
+ equivalent to the :option: `-X frozen_modules <-X> ` command-line option.
547
550
(Contributed by Yilei Yang in :gh: `111374 `.)
548
551
549
- * Add :ref: `support for the perf profiler <perf_profiling >` working without
550
- frame pointers through the new environment variable
551
- :envvar: `PYTHON_PERF_JIT_SUPPORT ` and command-line option :option: `-X perf_jit
552
- <-X> ` (Contributed by Pablo Galindo in :gh: `118518 `.)
553
-
554
- * The new :envvar: `PYTHON_HISTORY ` environment variable can be used to change
555
- the location of a ``.python_history `` file.
556
- (Contributed by Levi Sabah, Zackery Spytz and Hugo van Kemenade in
557
- :gh: `73965 `.)
558
-
559
- * Add :exc: `PythonFinalizationError ` exception. This exception derived from
560
- :exc: `RuntimeError ` is raised when an operation is blocked during
561
- the :term: `Python finalization <interpreter shutdown> `.
562
-
563
- The following functions now raise PythonFinalizationError, instead of
564
- :exc: `RuntimeError `:
565
-
566
- * :func: `_thread.start_new_thread `.
567
- * :class: `subprocess.Popen `.
568
- * :func: `os.fork `.
569
- * :func: `os.forkpty `.
570
-
571
- (Contributed by Victor Stinner in :gh: `114570 `.)
572
-
573
- * Added :attr: `!name ` and :attr: `!mode ` attributes for compressed
574
- and archived file-like objects in modules :mod: `bz2 `, :mod: `lzma `,
575
- :mod: `tarfile ` and :mod: `zipfile `.
576
- (Contributed by Serhiy Storchaka in :gh: `115961 `.)
577
-
578
- * Allow controlling Expat >=2.6.0 reparse deferral (:cve: `2023-52425 `)
579
- by adding five new methods:
552
+ * Add :ref: `support for the perf profiler <perf_profiling >` working
553
+ without `frame pointers <https://en.wikipedia.org/wiki/Call_stack >`_ through
554
+ the new environment variable :envvar: `PYTHON_PERF_JIT_SUPPORT `
555
+ and command-line option :option: `-X perf_jit <-X> `.
556
+ (Contributed by Pablo Galindo in :gh: `118518 `.)
580
557
581
- * :meth: `xml.etree.ElementTree.XMLParser.flush `
582
- * :meth: `xml.etree.ElementTree.XMLPullParser.flush `
583
- * :meth: `xml.parsers.expat.xmlparser.GetReparseDeferralEnabled `
584
- * :meth: `xml.parsers.expat.xmlparser.SetReparseDeferralEnabled `
585
- * :meth: `!xml.sax.expatreader.ExpatParser.flush `
558
+ * The location of a :file: `.python_history ` file can be changed via the
559
+ new :envvar: `PYTHON_HISTORY ` environment variable.
560
+ (Contributed by Levi Sabah, Zackery Spytz and Hugo van Kemenade
561
+ in :gh: `73965 `.)
586
562
587
- (Contributed by Sebastian Pipping in :gh: `115623 `.)
563
+ * Classes have a new :attr: `~class.__static_attributes__ ` attribute.
564
+ This is populated by the compiler with a tuple of the class's attribute names
565
+ which are assigned through ``self.<name> `` from any function in its body.
566
+ (Contributed by Irit Katriel in :gh: `115775 `.)
588
567
589
- * The :func: ` ssl.create_default_context ` API now includes
590
- :data: ` ssl.VERIFY_X509_PARTIAL_CHAIN ` and :data: ` ssl.VERIFY_X509_STRICT `
591
- in its default flags.
568
+ * The compiler now creates a :attr: ` !__firstlineno__ ` attribute on classes
569
+ with the line number of the first line of the class definition.
570
+ (Contributed by Serhiy Storchaka in :gh: ` 118465 `.)
592
571
593
- .. note ::
572
+ * The :func: `exec ` and :func: `eval ` builtins now accept
573
+ the *globals * and *locals * arguments as keywords.
574
+ (Contributed by Raphael Gaschignard in :gh: `105879 `)
594
575
595
- :data: `ssl.VERIFY_X509_STRICT ` may reject pre-:rfc: `5280 ` or malformed
596
- certificates that the underlying OpenSSL implementation otherwise would
597
- accept. While disabling this is not recommended, you can do so using::
576
+ * The :func: `compile ` builtin now accepts a new flag,
577
+ ``ast.PyCF_OPTIMIZED_AST ``, which is similar to ``ast.PyCF_ONLY_AST ``
578
+ except that the returned AST is optimized according to
579
+ the value of the *optimize * argument.
580
+ (Contributed by Irit Katriel in :gh: `108113 `).
598
581
599
- ctx = ssl.create_default_context()
600
- ctx.verify_flags &= ~ssl.VERIFY_X509_STRICT
582
+ * Add :exc: `PythonFinalizationError `, a new exception derived from
583
+ :exc: `RuntimeError ` and used to signal when operations are blocked
584
+ during :term: `finalization <interpreter shutdown> `.
585
+ The following callables now raise :exc: `!PythonFinalizationError `,
586
+ instead of :exc: `RuntimeError `:
601
587
602
- (Contributed by William Woodruff in :gh: `112389 `.)
588
+ * :func: `_thread.start_new_thread `
589
+ * :func: `os.fork `
590
+ * :func: `os.forkpty `
591
+ * :class: `subprocess.Popen `
603
592
604
- * The :class: `configparser.ConfigParser ` now accepts unnamed sections before named
605
- ones if configured to do so.
606
- (Contributed by Pedro Sousa Lacerda in :gh: `66449 `.)
593
+ (Contributed by Victor Stinner in :gh: `114570 `.)
607
594
608
- * :ref: `annotation scope <annotation-scopes >` within class scopes can now
609
- contain lambdas and comprehensions. Comprehensions that are located within
610
- class scopes are not inlined into their parent scope. (Contributed by
611
- Jelle Zijlstra in :gh: `109118 ` and :gh: `118160 `.)
595
+ * Allow the *count * argument of :meth: `str.replace ` to be a keyword.
596
+ (Contributed by Hugo van Kemenade in :gh: `106487 `.)
612
597
613
- * Classes have a new :attr: ` !__firstlineno__ ` attribute,
614
- populated by the compiler, with the line number of the first line
615
- of the class definition .
616
- (Contributed by Serhiy Storchaka in :gh: `118465 `.)
598
+ * Many functions now emit a warning if a boolean value is passed as
599
+ a file descriptor argument.
600
+ This can help catch some errors earlier .
601
+ (Contributed by Serhiy Storchaka in :gh: `82626 `.)
617
602
618
- * ``from __future__ import ... `` statements are now just normal
619
- relative imports if dots are present before the module name.
620
- (Contributed by Jeremiah Gabriel Pascual in :gh: `118216 `.)
603
+ * Added :attr: `!name ` and :attr: `!mode ` attributes
604
+ for compressed and archived file-like objects in
605
+ the :mod: `bz2 `, :mod: `lzma `, :mod: `tarfile `, and :mod: `zipfile ` modules.
606
+ (Contributed by Serhiy Storchaka in :gh: `115961 `.)
621
607
622
608
623
609
New Modules
624
610
===========
625
611
626
- * :mod: `dbm.sqlite3 `: SQLite backend for :mod: `dbm `.
612
+ * :mod: `dbm.sqlite3 `: An SQLite backend for :mod: `dbm `.
627
613
(Contributed by Raymond Hettinger and Erlend E. Aasland in :gh: `100414 `.)
628
614
629
615
@@ -748,6 +734,23 @@ base64
748
734
See the `Z85 specification <https://rfc.zeromq.org/spec/32/ >`_ for more information.
749
735
(Contributed by Matan Perelman in :gh: `75299 `.)
750
736
737
+
738
+ compileall
739
+ ----------
740
+
741
+ * Select the default number of worker threads and processes using
742
+ :func: `os.process_cpu_count ` instead of :func: `os.cpu_count `.
743
+ (Contributed by Victor Stinner in :gh: `109649 `.)
744
+
745
+
746
+ concurrent.futures
747
+ ------------------
748
+
749
+ * Select the default number of worker threads and processes using
750
+ :func: `os.process_cpu_count ` instead of :func: `os.cpu_count `.
751
+ (Contributed by Victor Stinner in :gh: `109649 `.)
752
+
753
+
751
754
copy
752
755
----
753
756
@@ -953,6 +956,15 @@ mmap
953
956
is inaccessible due to file system errors or access violations.
954
957
(Contributed by Jannis Weigend in :gh: `118209 `.)
955
958
959
+
960
+ multiprocessing
961
+ ---------------
962
+
963
+ * Select the default number of worker threads and processes using
964
+ :func: `os.process_cpu_count ` instead of :func: `os.cpu_count `.
965
+ (Contributed by Victor Stinner in :gh: `109649 `.)
966
+
967
+
956
968
opcode
957
969
------
958
970
@@ -1017,10 +1029,15 @@ os.path
1017
1029
* Add :func: `os.path.isreserved ` to check if a path is reserved on the current
1018
1030
system. This function is only available on Windows.
1019
1031
(Contributed by Barney Gale in :gh: `88569 `.)
1032
+
1020
1033
* On Windows, :func: `os.path.isabs ` no longer considers paths starting with
1021
1034
exactly one (back)slash to be absolute.
1022
1035
(Contributed by Barney Gale and Jon Foster in :gh: `44626 `.)
1023
1036
1037
+ * :func: `os.path.realpath ` now resolves MS-DOS style file names even if
1038
+ the file is not accessible.
1039
+ (Contributed by Moonsik Park in :gh: `82367 `.)
1040
+
1024
1041
* Add support of *dir_fd * and *follow_symlinks * keyword arguments in
1025
1042
:func: `shutil.chown `.
1026
1043
(Contributed by Berker Peksag and Tahia K in :gh: `62308 `)
@@ -1120,6 +1137,26 @@ sqlite3
1120
1137
for filtering database objects to dump.
1121
1138
(Contributed by Mariusz Felisiak in :gh: `91602 `.)
1122
1139
1140
+
1141
+ ssl
1142
+ ---
1143
+
1144
+ * The :func: `ssl.create_default_context ` API now includes
1145
+ :data: `ssl.VERIFY_X509_PARTIAL_CHAIN ` and :data: `ssl.VERIFY_X509_STRICT `
1146
+ in its default flags.
1147
+
1148
+ .. note ::
1149
+
1150
+ :data: `ssl.VERIFY_X509_STRICT ` may reject pre-:rfc: `5280 ` or malformed
1151
+ certificates that the underlying OpenSSL implementation otherwise would
1152
+ accept. While disabling this is not recommended, you can do so using::
1153
+
1154
+ ctx = ssl.create_default_context()
1155
+ ctx.verify_flags &= ~ssl.VERIFY_X509_STRICT
1156
+
1157
+ (Contributed by William Woodruff in :gh: `112389 `.)
1158
+
1159
+
1123
1160
statistics
1124
1161
----------
1125
1162
@@ -1285,13 +1322,26 @@ warnings
1285
1322
warning may also be emitted when a decorated function or class is used at runtime.
1286
1323
See :pep: `702 `. (Contributed by Jelle Zijlstra in :gh: `104003 `.)
1287
1324
1288
- xml.etree.ElementTree
1289
- ---------------------
1325
+
1326
+ xml
1327
+ ---
1328
+
1329
+ * Allow controlling Expat >=2.6.0 reparse deferral (:cve: `2023-52425 `)
1330
+ by adding five new methods:
1331
+
1332
+ * :meth: `xml.etree.ElementTree.XMLParser.flush `
1333
+ * :meth: `xml.etree.ElementTree.XMLPullParser.flush `
1334
+ * :meth: `xml.parsers.expat.xmlparser.GetReparseDeferralEnabled `
1335
+ * :meth: `xml.parsers.expat.xmlparser.SetReparseDeferralEnabled `
1336
+ * :meth: `!xml.sax.expatreader.ExpatParser.flush `
1337
+
1338
+ (Contributed by Sebastian Pipping in :gh: `115623 `.)
1290
1339
1291
1340
* Add the :meth: `!close ` method for the iterator returned by
1292
1341
:func: `~xml.etree.ElementTree.iterparse ` for explicit cleaning up.
1293
1342
(Contributed by Serhiy Storchaka in :gh: `69893 `.)
1294
1343
1344
+
1295
1345
zipimport
1296
1346
---------
1297
1347
@@ -1447,6 +1497,10 @@ PEP 594: dead batteries (and other module removals)
1447
1497
configparser
1448
1498
------------
1449
1499
1500
+ * The :class: `configparser.ConfigParser ` now accepts unnamed sections
1501
+ before named ones if configured to do so.
1502
+ (Contributed by Pedro Sousa Lacerda in :gh: `66449 `.)
1503
+
1450
1504
* Remove the undocumented :class: `!configparser.LegacyInterpolation ` class,
1451
1505
deprecated in the docstring since Python 3.2,
1452
1506
and with a deprecation warning since Python 3.11.
0 commit comments