forked from python/python-docs-tr
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3.11.html
More file actions
2961 lines (2914 loc) · 344 KB
/
3.11.html
File metadata and controls
2961 lines (2914 loc) · 344 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta property="og:title" content="What’s New In Python 3.11" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/whatsnew/3.11.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Editor, Pablo Galindo Salgado,. This article explains the new features in Python 3.11, compared to 3.10. For full details, see the changelog. Summary – Release highlights: Python 3.11 is between 10..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Editor, Pablo Galindo Salgado,. This article explains the new features in Python 3.11, compared to 3.10. For full details, see the changelog. Summary – Release highlights: Python 3.11 is between 10..." />
<meta property="og:image:width" content="200" />
<meta property="og:image:height" content="200" />
<meta name="theme-color" content="#3776ab" />
<title>What’s New In Python 3.11 — Python 3.11.5 belgelendirmesi</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?digest=b37c26da2f7529d09fe70b41c4b2133fe4931a90" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/sphinx_highlight.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Python 3.11.5 belgelendirmesi içinde ara"
href="../_static/opensearch.xml"/>
<link rel="author" title="Bu belgeler hakkında" href="../about.html" />
<link rel="index" title="Dizin" href="../genindex.html" />
<link rel="search" title="Ara" href="../search.html" />
<link rel="copyright" title="Telif Hakkı" href="../copyright.html" />
<link rel="next" title="What’s New In Python 3.10" href="3.10.html" />
<link rel="prev" title="What’s New in Python" href="index.html" />
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.11.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg>
<input placeholder="Hızlı Arama" aria-label="Hızlı Arama" type="search" name="q" />
<input type="submit" value="Git"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">İçindekiler</a></h3>
<ul>
<li><a class="reference internal" href="#">What’s New In Python 3.11</a><ul>
<li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
<li><a class="reference internal" href="#new-features">New Features</a><ul>
<li><a class="reference internal" href="#pep-657-fine-grained-error-locations-in-tracebacks">PEP 657: Fine-grained error locations in tracebacks</a></li>
<li><a class="reference internal" href="#pep-654-exception-groups-and-except">PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code></a></li>
<li><a class="reference internal" href="#pep-678-exceptions-can-be-enriched-with-notes">PEP 678: Exceptions can be enriched with notes</a></li>
<li><a class="reference internal" href="#windows-py-exe-launcher-improvements">Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements</a></li>
</ul>
</li>
<li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
<li><a class="reference internal" href="#pep-646-variadic-generics">PEP 646: Variadic generics</a></li>
<li><a class="reference internal" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required">PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required</a></li>
<li><a class="reference internal" href="#pep-673-self-type">PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type</a></li>
<li><a class="reference internal" href="#pep-675-arbitrary-literal-string-type">PEP 675: Arbitrary literal string type</a></li>
<li><a class="reference internal" href="#pep-681-data-class-transforms">PEP 681: Data class transforms</a></li>
<li><a class="reference internal" href="#pep-563-may-not-be-the-future">PEP 563 may not be the future</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
<li><a class="reference internal" href="#other-cpython-implementation-changes">Other CPython Implementation Changes</a></li>
<li><a class="reference internal" href="#new-modules">New Modules</a></li>
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
<li><a class="reference internal" href="#dataclasses">dataclasses</a></li>
<li><a class="reference internal" href="#datetime">datetime</a></li>
<li><a class="reference internal" href="#enum">enum</a></li>
<li><a class="reference internal" href="#fcntl">fcntl</a></li>
<li><a class="reference internal" href="#fractions">fractions</a></li>
<li><a class="reference internal" href="#functools">functools</a></li>
<li><a class="reference internal" href="#hashlib">hashlib</a></li>
<li><a class="reference internal" href="#whatsnew311-idle">IDLE and idlelib</a></li>
<li><a class="reference internal" href="#inspect">inspect</a></li>
<li><a class="reference internal" href="#locale">locale</a></li>
<li><a class="reference internal" href="#logging">logging</a></li>
<li><a class="reference internal" href="#math">math</a></li>
<li><a class="reference internal" href="#operator">operator</a></li>
<li><a class="reference internal" href="#os">os</a></li>
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
<li><a class="reference internal" href="#re">re</a></li>
<li><a class="reference internal" href="#shutil">shutil</a></li>
<li><a class="reference internal" href="#socket">socket</a></li>
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
<li><a class="reference internal" href="#string">string</a></li>
<li><a class="reference internal" href="#sys">sys</a></li>
<li><a class="reference internal" href="#sysconfig">sysconfig</a></li>
<li><a class="reference internal" href="#tempfile">tempfile</a></li>
<li><a class="reference internal" href="#threading">threading</a></li>
<li><a class="reference internal" href="#time">time</a></li>
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
<li><a class="reference internal" href="#traceback">traceback</a></li>
<li><a class="reference internal" href="#typing">typing</a></li>
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
<li><a class="reference internal" href="#unittest">unittest</a></li>
<li><a class="reference internal" href="#venv">venv</a></li>
<li><a class="reference internal" href="#warnings">warnings</a></li>
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
</ul>
</li>
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
<li><a class="reference internal" href="#faster-cpython">Faster CPython</a><ul>
<li><a class="reference internal" href="#faster-startup">Faster Startup</a><ul>
<li><a class="reference internal" href="#frozen-imports-static-code-objects">Frozen imports / Static code objects</a></li>
</ul>
</li>
<li><a class="reference internal" href="#faster-runtime">Faster Runtime</a><ul>
<li><a class="reference internal" href="#cheaper-lazy-python-frames">Cheaper, lazy Python frames</a></li>
<li><a class="reference internal" href="#inlined-python-function-calls">Inlined Python function calls</a></li>
<li><a class="reference internal" href="#pep-659-specializing-adaptive-interpreter">PEP 659: Specializing Adaptive Interpreter</a></li>
</ul>
</li>
<li><a class="reference internal" href="#misc">Misc</a></li>
<li><a class="reference internal" href="#faq">FAQ</a><ul>
<li><a class="reference internal" href="#how-should-i-write-my-code-to-utilize-these-speedups">How should I write my code to utilize these speedups?</a></li>
<li><a class="reference internal" href="#will-cpython-3-11-use-more-memory">Will CPython 3.11 use more memory?</a></li>
<li><a class="reference internal" href="#i-don-t-see-any-speedups-in-my-workload-why">I don’t see any speedups in my workload. Why?</a></li>
<li><a class="reference internal" href="#is-there-a-jit-compiler">Is there a JIT compiler?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#about">About</a></li>
</ul>
</li>
<li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a><ul>
<li><a class="reference internal" href="#new-opcodes">New opcodes</a></li>
<li><a class="reference internal" href="#replaced-opcodes">Replaced opcodes</a></li>
<li><a class="reference internal" href="#changed-removed-opcodes">Changed/removed opcodes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
<li><a class="reference internal" href="#language-builtins">Language/Builtins</a></li>
<li><a class="reference internal" href="#modules">Modules</a></li>
<li><a class="reference internal" href="#standard-library">Standard Library</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pending-removal-in-python-3-12">Pending Removal in Python 3.12</a></li>
<li><a class="reference internal" href="#removed">Removed</a></li>
<li><a class="reference internal" href="#porting-to-python-3-11">Porting to Python 3.11</a></li>
<li><a class="reference internal" href="#build-changes">Build Changes</a></li>
<li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
<li><a class="reference internal" href="#whatsnew311-c-api-new-features">New Features</a></li>
<li><a class="reference internal" href="#whatsnew311-c-api-porting">Porting to Python 3.11</a></li>
<li><a class="reference internal" href="#whatsnew311-c-api-deprecated">Deprecated</a></li>
<li><a class="reference internal" href="#whatsnew311-c-api-pending-removal">Pending Removal in Python 3.12</a></li>
<li><a class="reference internal" href="#whatsnew311-c-api-removed">Removed</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-3-11-4">Notable Changes in 3.11.4</a><ul>
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-3-11-5">Notable Changes in 3.11.5</a><ul>
<li><a class="reference internal" href="#openssl">OpenSSL</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Önceki konu</h4>
<p class="topless"><a href="index.html"
title="önceki bölüm">What’s New in Python</a></p>
</div>
<div>
<h4>Sonraki konu</h4>
<p class="topless"><a href="3.10.html"
title="sonraki bölüm">What’s New In Python 3.10</a></p>
</div>
<div role="note" aria-label="source link">
<h3>Bu Sayfa</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Hata Bildir</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.11/Doc/whatsnew/3.11.rst"
rel="nofollow">Kaynağı Göster
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Gezinti</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="Genel Endeks"
accesskey="I">dizin</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Modül Dizini"
>modülleri</a> |</li>
<li class="right" >
<a href="3.10.html" title="What’s New In Python 3.10"
accesskey="N">sonraki</a> |</li>
<li class="right" >
<a href="index.html" title="What’s New in Python"
accesskey="P">önceki</a> |</li>
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.11.5 Documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li>
<li class="nav-item nav-item-this"><a href="">What’s New In Python 3.11</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Hızlı Arama" aria-label="Hızlı Arama" type="search" name="q" id="search-box" />
<input type="submit" value="Git" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="what-s-new-in-python-3-11">
<h1>What’s New In Python 3.11<a class="headerlink" href="#what-s-new-in-python-3-11" title="Permalink to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Editor<span class="colon">:</span></dt>
<dd class="field-odd"><p>Pablo Galindo Salgado</p>
</dd>
</dl>
<p>This article explains the new features in Python 3.11, compared to 3.10.</p>
<p>For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
<section id="summary-release-highlights">
<span id="whatsnew311-summary"></span><h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Permalink to this heading">¶</a></h2>
<ul class="simple">
<li><p>Python 3.11 is between 10-60% faster than Python 3.10.
On average, we measured a 1.25x speedup on the standard benchmark suite.
See <a class="reference internal" href="#whatsnew311-faster-cpython"><span class="std std-ref">Faster CPython</span></a> for details.</p></li>
</ul>
<p>New syntax features:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew311-pep654"><span class="std std-ref">PEP 654: Exception Groups and except*</span></a></p></li>
</ul>
<p>New built-in features:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew311-pep678"><span class="std std-ref">PEP 678: Exceptions can be enriched with notes</span></a></p></li>
</ul>
<p>New standard library modules:</p>
<ul class="simple">
<li><p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0680/"><strong>PEP 680</strong></a>: <a class="reference internal" href="../library/tomllib.html#module-tomllib" title="tomllib: Parse TOML files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code></a> —
Support for parsing <a class="reference external" href="https://toml.io/">TOML</a> in the Standard Library</p></li>
</ul>
<p>Interpreter improvements:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew311-pep657"><span class="std std-ref">PEP 657: Fine-grained error locations in tracebacks</span></a></p></li>
<li><p>New <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command line option and <span class="target" id="index-1"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment
variable to <a class="reference internal" href="#whatsnew311-pythonsafepath"><span class="std std-ref">disable automatically prepending potentially unsafe paths</span></a> to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a></p></li>
</ul>
<p>New typing features:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew311-pep646"><span class="std std-ref">PEP 646: Variadic generics</span></a></p></li>
<li><p><a class="reference internal" href="#whatsnew311-pep655"><span class="std std-ref">PEP 655: Marking individual TypedDict items as required or not-required</span></a></p></li>
<li><p><a class="reference internal" href="#whatsnew311-pep673"><span class="std std-ref">PEP 673: Self type</span></a></p></li>
<li><p><a class="reference internal" href="#whatsnew311-pep675"><span class="std std-ref">PEP 675: Arbitrary literal string type</span></a></p></li>
<li><p><a class="reference internal" href="#whatsnew311-pep681"><span class="std std-ref">PEP 681: Data class transforms</span></a></p></li>
</ul>
<p>Important deprecations, removals and restrictions:</p>
<ul class="simple">
<li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>:
<a class="reference internal" href="#whatsnew311-pep594"><span class="std std-ref">Many legacy standard library modules have been deprecated</span></a> and will be removed in Python 3.13</p></li>
<li><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/"><strong>PEP 624</strong></a>:
<a class="reference internal" href="#whatsnew311-pep624"><span class="std std-ref">Py_UNICODE encoder APIs have been removed</span></a></p></li>
<li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0670/"><strong>PEP 670</strong></a>:
<a class="reference internal" href="#whatsnew311-pep670"><span class="std std-ref">Macros converted to static inline functions</span></a></p></li>
</ul>
</section>
<section id="new-features">
<span id="whatsnew311-features"></span><h2>New Features<a class="headerlink" href="#new-features" title="Permalink to this heading">¶</a></h2>
<section id="pep-657-fine-grained-error-locations-in-tracebacks">
<span id="whatsnew311-pep657"></span><h3>PEP 657: Fine-grained error locations in tracebacks<a class="headerlink" href="#pep-657-fine-grained-error-locations-in-tracebacks" title="Permalink to this heading">¶</a></h3>
<p>When printing tracebacks, the interpreter will now point to the exact expression
that caused the error, instead of just the line. For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
<span class="n">File</span> <span class="s2">"distance.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">11</span><span class="p">,</span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
<span class="nb">print</span><span class="p">(</span><span class="n">manhattan_distance</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">))</span>
<span class="o">^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
<span class="n">File</span> <span class="s2">"distance.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">6</span><span class="p">,</span> <span class="ow">in</span> <span class="n">manhattan_distance</span>
<span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">point_1</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">point_2</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">point_1</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">point_2</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
<span class="o">^^^^^^^^^</span>
<span class="ne">AttributeError</span><span class="p">:</span> <span class="s1">'NoneType'</span> <span class="nb">object</span> <span class="n">has</span> <span class="n">no</span> <span class="n">attribute</span> <span class="s1">'x'</span>
</pre></div>
</div>
<p>Previous versions of the interpreter would point to just the line, making it
ambiguous which object was <code class="docutils literal notranslate"><span class="pre">None</span></code>. These enhanced errors can also be helpful
when dealing with deeply nested <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> objects and multiple function calls:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">37</span><span class="p">,</span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
<span class="n">magic_arithmetic</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span>
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">18</span><span class="p">,</span> <span class="ow">in</span> <span class="n">magic_arithmetic</span>
<span class="k">return</span> <span class="n">add_counts</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="mi">25</span>
<span class="o">^^^^^^^^^^^^^</span>
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">24</span><span class="p">,</span> <span class="ow">in</span> <span class="n">add_counts</span>
<span class="k">return</span> <span class="mi">25</span> <span class="o">+</span> <span class="n">query_user</span><span class="p">(</span><span class="n">user1</span><span class="p">)</span> <span class="o">+</span> <span class="n">query_user</span><span class="p">(</span><span class="n">user2</span><span class="p">)</span>
<span class="o">^^^^^^^^^^^^^^^^^</span>
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">32</span><span class="p">,</span> <span class="ow">in</span> <span class="n">query_user</span>
<span class="k">return</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">query_count</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">response</span><span class="p">[</span><span class="s1">'a'</span><span class="p">][</span><span class="s1">'b'</span><span class="p">][</span><span class="s1">'c'</span><span class="p">][</span><span class="s1">'user'</span><span class="p">],</span> <span class="n">retry</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="o">~~~~~~~~~~~~~~~~~~^^^^^</span>
<span class="ne">TypeError</span><span class="p">:</span> <span class="s1">'NoneType'</span> <span class="nb">object</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">subscriptable</span>
</pre></div>
</div>
<p>As well as complex arithmetic expressions:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
<span class="n">File</span> <span class="s2">"calculation.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">54</span><span class="p">,</span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
<span class="n">result</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span> <span class="o">/</span> <span class="n">y</span> <span class="o">/</span> <span class="n">z</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">a</span> <span class="o">/</span> <span class="n">b</span> <span class="o">/</span> <span class="n">c</span><span class="p">)</span>
<span class="o">~~~~~~^~~</span>
<span class="ne">ZeroDivisionError</span><span class="p">:</span> <span class="n">division</span> <span class="n">by</span> <span class="n">zero</span>
</pre></div>
</div>
<p>Additionally, the information used by the enhanced traceback feature
is made available via a general API, that can be used to correlate
<a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> <a class="reference internal" href="../library/dis.html#bytecodes"><span class="std std-ref">instructions</span></a> with source code location.
This information can be retrieved using:</p>
<ul class="simple">
<li><p>The <a class="reference internal" href="../reference/datamodel.html#codeobject.co_positions" title="codeobject.co_positions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codeobject.co_positions()</span></code></a> method in Python.</p></li>
<li><p>The <a class="reference internal" href="../c-api/code.html#c.PyCode_Addr2Location" title="PyCode_Addr2Location"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_Addr2Location()</span></code></a> function in the C API.</p></li>
</ul>
<p>See <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0657/"><strong>PEP 657</strong></a> for more details. (Contributed by Pablo Galindo, Batuhan Taskaya
and Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43950">bpo-43950</a>.)</p>
<div class="admonition note">
<p class="admonition-title">Not</p>
<p>This feature requires storing column positions in <a class="reference internal" href="../c-api/code.html#codeobjects"><span class="std std-ref">Code Objects</span></a>,
which may result in a small increase in interpreter memory usage
and disk usage for compiled Python files.
To avoid storing the extra information
and deactivate printing the extra traceback information,
use the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">no_debug_ranges</span></code></a> command line option
or the <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONNODEBUGRANGES"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONNODEBUGRANGES</span></code></a> environment variable.</p>
</div>
</section>
<section id="pep-654-exception-groups-and-except">
<span id="whatsnew311-pep654"></span><h3>PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code><a class="headerlink" href="#pep-654-exception-groups-and-except" title="Permalink to this heading">¶</a></h3>
<p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a> introduces language features that enable a program
to raise and handle multiple unrelated exceptions simultaneously.
The builtin types <a class="reference internal" href="../library/exceptions.html#ExceptionGroup" title="ExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExceptionGroup</span></code></a> and <a class="reference internal" href="../library/exceptions.html#BaseExceptionGroup" title="BaseExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseExceptionGroup</span></code></a>
make it possible to group exceptions and raise them together,
and the new <a class="reference internal" href="../reference/compound_stmts.html#except-star"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except*</span></code></a> syntax generalizes
<a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> to match subgroups of exception groups.</p>
<p>See <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a> for more details.</p>
<p>(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45292">bpo-45292</a>. PEP written by
Irit Katriel, Yury Selivanov and Guido van Rossum.)</p>
</section>
<section id="pep-678-exceptions-can-be-enriched-with-notes">
<span id="whatsnew311-pep678"></span><h3>PEP 678: Exceptions can be enriched with notes<a class="headerlink" href="#pep-678-exceptions-can-be-enriched-with-notes" title="Permalink to this heading">¶</a></h3>
<p>The <a class="reference internal" href="../library/exceptions.html#BaseException.add_note" title="BaseException.add_note"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_note()</span></code></a> method is added to <a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a>.
It can be used to enrich exceptions with context information
that is not available at the time when the exception is raised.
The added notes appear in the default traceback.</p>
<p>See <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0678/"><strong>PEP 678</strong></a> for more details.</p>
<p>(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45607">bpo-45607</a>.
PEP written by Zac Hatfield-Dodds.)</p>
</section>
<section id="windows-py-exe-launcher-improvements">
<span id="whatsnew311-windows-launcher"></span><h3>Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements<a class="headerlink" href="#windows-py-exe-launcher-improvements" title="Permalink to this heading">¶</a></h3>
<p>The copy of the <a class="reference internal" href="../using/windows.html#launcher"><span class="std std-ref">Python Launcher for Windows</span></a> included with Python 3.11 has been significantly
updated. It now supports company/tag syntax as defined in <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0514/"><strong>PEP 514</strong></a> using the
<code class="docutils literal notranslate"><span class="pre">-V:<company>/<tag></span></code> argument instead of the limited <code class="docutils literal notranslate"><span class="pre">-<major>.<minor></span></code>.
This allows launching distributions other than <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>,
the one hosted on <a class="reference external" href="https://www.python.org">python.org</a>.</p>
<p>When using <code class="docutils literal notranslate"><span class="pre">-V:</span></code> selectors, either company or tag can be omitted, but all
installs will be searched. For example, <code class="docutils literal notranslate"><span class="pre">-V:OtherPython/</span></code> will select the
“best” tag registered for <code class="docutils literal notranslate"><span class="pre">OtherPython</span></code>, while <code class="docutils literal notranslate"><span class="pre">-V:3.11</span></code> or <code class="docutils literal notranslate"><span class="pre">-V:/3.11</span></code>
will select the “best” distribution with tag <code class="docutils literal notranslate"><span class="pre">3.11</span></code>.</p>
<p>When using the legacy <code class="docutils literal notranslate"><span class="pre">-<major></span></code>, <code class="docutils literal notranslate"><span class="pre">-<major>.<minor></span></code>,
<code class="docutils literal notranslate"><span class="pre">-<major>-<bitness></span></code> or <code class="docutils literal notranslate"><span class="pre">-<major>.<minor>-<bitness></span></code> arguments,
all existing behaviour should be preserved from past versions,
and only releases from <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code> will be selected.
However, the <code class="docutils literal notranslate"><span class="pre">-64</span></code> suffix now implies “not 32-bit” (not necessarily x86-64),
as there are multiple supported 64-bit platforms.
32-bit runtimes are detected by checking the runtime’s tag for a <code class="docutils literal notranslate"><span class="pre">-32</span></code> suffix.
All releases of Python since 3.5 have included this in their 32-bit builds.</p>
</section>
</section>
<section id="new-features-related-to-type-hints">
<span id="whatsnew311-typing-features"></span><span id="new-feat-related-type-hints-311"></span><h2>New Features Related to Type Hints<a class="headerlink" href="#new-features-related-to-type-hints" title="Permalink to this heading">¶</a></h2>
<p>This section covers major changes affecting <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> type hints and
the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module.</p>
<section id="pep-646-variadic-generics">
<span id="whatsnew311-pep646"></span><h3>PEP 646: Variadic generics<a class="headerlink" href="#pep-646-variadic-generics" title="Permalink to this heading">¶</a></h3>
<p><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> previously introduced <a class="reference internal" href="../library/typing.html#typing.TypeVar" title="typing.TypeVar"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVar</span></code></a>, enabling creation
of generics parameterised with a single type. <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0646/"><strong>PEP 646</strong></a> adds
<a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a>, enabling parameterisation
with an <em>arbitrary</em> number of types. In other words,
a <a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a> is a <em>variadic</em> type variable,
enabling <em>variadic</em> generics.</p>
<p>This enables a wide variety of use cases.
In particular, it allows the type of array-like structures
in numerical computing libraries such as NumPy and TensorFlow to be
parameterised with the array <em>shape</em>. Static type checkers will now
be able to catch shape-related bugs in code that uses these libraries.</p>
<p>See <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0646/"><strong>PEP 646</strong></a> for more details.</p>
<p>(Contributed by Matthew Rahtz in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43224">bpo-43224</a>, with contributions by
Serhiy Storchaka and Jelle Zijlstra. PEP written by Mark Mendoza, Matthew
Rahtz, Pradeep Kumar Srinivasan, and Vincent Siles.)</p>
</section>
<section id="pep-655-marking-individual-typeddict-items-as-required-or-not-required">
<span id="whatsnew311-pep655"></span><h3>PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required<a class="headerlink" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required" title="Permalink to this heading">¶</a></h3>
<p><a class="reference internal" href="../library/typing.html#typing.Required" title="typing.Required"><code class="xref py py-data docutils literal notranslate"><span class="pre">Required</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.NotRequired" title="typing.NotRequired"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotRequired</span></code></a> provide a
straightforward way to mark whether individual items in a
<a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypedDict</span></code></a> must be present. Previously, this was only possible
using inheritance.</p>
<p>All fields are still required by default,
unless the <em>total</em> parameter is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>,
in which case all fields are still not-required by default.
For example, the following specifies a <code class="xref py py-class docutils literal notranslate"><span class="pre">TypedDict</span></code>
with one required and one not-required key:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">):</span>
<span class="n">title</span><span class="p">:</span> <span class="nb">str</span>
<span class="n">year</span><span class="p">:</span> <span class="n">NotRequired</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span>
<span class="n">m1</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"title"</span><span class="p">:</span> <span class="s2">"Black Panther"</span><span class="p">,</span> <span class="s2">"year"</span><span class="p">:</span> <span class="mi">2018</span><span class="p">}</span> <span class="c1"># OK</span>
<span class="n">m2</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"title"</span><span class="p">:</span> <span class="s2">"Star Wars"</span><span class="p">}</span> <span class="c1"># OK (year is not required)</span>
<span class="n">m3</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"year"</span><span class="p">:</span> <span class="mi">2022</span><span class="p">}</span> <span class="c1"># ERROR (missing required field title)</span>
</pre></div>
</div>
<p>The following definition is equivalent:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">title</span><span class="p">:</span> <span class="n">Required</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span>
<span class="n">year</span><span class="p">:</span> <span class="nb">int</span>
</pre></div>
</div>
<p>See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0655/"><strong>PEP 655</strong></a> for more details.</p>
<p>(Contributed by David Foster and Jelle Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47087">bpo-47087</a>. PEP
written by David Foster.)</p>
</section>
<section id="pep-673-self-type">
<span id="whatsnew311-pep673"></span><h3>PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type<a class="headerlink" href="#pep-673-self-type" title="Permalink to this heading">¶</a></h3>
<p>The new <a class="reference internal" href="../library/typing.html#typing.Self" title="typing.Self"><code class="xref py py-data docutils literal notranslate"><span class="pre">Self</span></code></a> annotation provides a simple and intuitive
way to annotate methods that return an instance of their class. This
behaves the same as the <a class="reference internal" href="../library/typing.html#typing.TypeVar" title="typing.TypeVar"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeVar</span></code></a>-based approach
<span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/#annotating-instance-and-class-methods"><strong>specified in PEP 484</strong></a>,
but is more concise and easier to follow.</p>
<p>Common use cases include alternative constructors provided as
<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod</span></code></a>s,
and <a class="reference internal" href="../reference/datamodel.html#object.__enter__" title="object.__enter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__enter__()</span></code></a> methods that return <code class="docutils literal notranslate"><span class="pre">self</span></code>:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyLock</span><span class="p">:</span>
<span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Self</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lock</span><span class="p">()</span>
<span class="k">return</span> <span class="bp">self</span>
<span class="o">...</span>
<span class="k">class</span> <span class="nc">MyInt</span><span class="p">:</span>
<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">fromhex</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">s</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Self</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">16</span><span class="p">))</span>
<span class="o">...</span>
</pre></div>
</div>
<p><a class="reference internal" href="../library/typing.html#typing.Self" title="typing.Self"><code class="xref py py-data docutils literal notranslate"><span class="pre">Self</span></code></a> can also be used to annotate method parameters
or attributes of the same type as their enclosing class.</p>
<p>See <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0673/"><strong>PEP 673</strong></a> for more details.</p>
<p>(Contributed by James Hilton-Balfe in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46534">bpo-46534</a>. PEP written by
Pradeep Kumar Srinivasan and James Hilton-Balfe.)</p>
</section>
<section id="pep-675-arbitrary-literal-string-type">
<span id="whatsnew311-pep675"></span><h3>PEP 675: Arbitrary literal string type<a class="headerlink" href="#pep-675-arbitrary-literal-string-type" title="Permalink to this heading">¶</a></h3>
<p>The new <a class="reference internal" href="../library/typing.html#typing.LiteralString" title="typing.LiteralString"><code class="xref py py-data docutils literal notranslate"><span class="pre">LiteralString</span></code></a> annotation may be used to indicate
that a function parameter can be of any literal string type. This allows
a function to accept arbitrary literal string types, as well as strings
created from other literal strings. Type checkers can then
enforce that sensitive functions, such as those that execute SQL
statements or shell commands, are called only with static arguments,
providing protection against injection attacks.</p>
<p>For example, a SQL query function could be annotated as follows:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">run_query</span><span class="p">(</span><span class="n">sql</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">)</span> <span class="o">-></span> <span class="o">...</span>
<span class="o">...</span>
<span class="k">def</span> <span class="nf">caller</span><span class="p">(</span>
<span class="n">arbitrary_string</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">query_string</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">,</span>
<span class="n">table_name</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span>
<span class="n">run_query</span><span class="p">(</span><span class="s2">"SELECT * FROM students"</span><span class="p">)</span> <span class="c1"># ok</span>
<span class="n">run_query</span><span class="p">(</span><span class="n">query_string</span><span class="p">)</span> <span class="c1"># ok</span>
<span class="n">run_query</span><span class="p">(</span><span class="s2">"SELECT * FROM "</span> <span class="o">+</span> <span class="n">table_name</span><span class="p">)</span> <span class="c1"># ok</span>
<span class="n">run_query</span><span class="p">(</span><span class="n">arbitrary_string</span><span class="p">)</span> <span class="c1"># type checker error</span>
<span class="n">run_query</span><span class="p">(</span> <span class="c1"># type checker error</span>
<span class="sa">f</span><span class="s2">"SELECT * FROM students WHERE name = </span><span class="si">{</span><span class="n">arbitrary_string</span><span class="si">}</span><span class="s2">"</span>
<span class="p">)</span>
</pre></div>
</div>
<p>See <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0675/"><strong>PEP 675</strong></a> for more details.</p>
<p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47088">bpo-47088</a>. PEP written by Pradeep
Kumar Srinivasan and Graham Bleaney.)</p>
</section>
<section id="pep-681-data-class-transforms">
<span id="whatsnew311-pep681"></span><h3>PEP 681: Data class transforms<a class="headerlink" href="#pep-681-data-class-transforms" title="Permalink to this heading">¶</a></h3>
<p><a class="reference internal" href="../library/typing.html#typing.dataclass_transform" title="typing.dataclass_transform"><code class="xref py py-data docutils literal notranslate"><span class="pre">dataclass_transform</span></code></a> may be used to
decorate a class, metaclass, or a function that is itself a decorator.
The presence of <code class="docutils literal notranslate"><span class="pre">@dataclass_transform()</span></code> tells a static type checker that the
decorated object performs runtime “magic” that transforms a class,
giving it <a class="reference internal" href="../library/dataclasses.html#dataclasses.dataclass" title="dataclasses.dataclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">dataclass</span></code></a>-like behaviors.</p>
<p>For example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># The create_model decorator is defined by a library.</span>
<span class="nd">@typing</span><span class="o">.</span><span class="n">dataclass_transform</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">create_model</span><span class="p">(</span><span class="bp">cls</span><span class="p">:</span> <span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">])</span> <span class="o">-></span> <span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">]:</span>
<span class="bp">cls</span><span class="o">.</span><span class="fm">__init__</span> <span class="o">=</span> <span class="o">...</span>
<span class="bp">cls</span><span class="o">.</span><span class="fm">__eq__</span> <span class="o">=</span> <span class="o">...</span>
<span class="bp">cls</span><span class="o">.</span><span class="fm">__ne__</span> <span class="o">=</span> <span class="o">...</span>
<span class="k">return</span> <span class="bp">cls</span>
<span class="c1"># The create_model decorator can now be used to create new model classes:</span>
<span class="nd">@create_model</span>
<span class="k">class</span> <span class="nc">CustomerModel</span><span class="p">:</span>
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">CustomerModel</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="mi">327</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">"Eric Idle"</span><span class="p">)</span>
</pre></div>
</div>
<p>See <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0681/"><strong>PEP 681</strong></a> for more details.</p>
<p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/91860">gh-91860</a>. PEP written by
Erik De Bonte and Eric Traut.)</p>
</section>
<section id="pep-563-may-not-be-the-future">
<span id="whatsnew311-pep563-deferred"></span><h3>PEP 563 may not be the future<a class="headerlink" href="#pep-563-may-not-be-the-future" title="Permalink to this heading">¶</a></h3>
<p><span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0563/"><strong>PEP 563</strong></a> Postponed Evaluation of Annotations
(the <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">annotations</span></code> <a class="reference internal" href="../reference/simple_stmts.html#future"><span class="std std-ref">future statement</span></a>)
that was originally planned for release in Python 3.10
has been put on hold indefinitely.
See <a class="reference external" href="https://mail.python.org/archives/list/python-dev@python.org/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/">this message from the Steering Council</a>
for more information.</p>
</section>
</section>
<section id="other-language-changes">
<span id="whatsnew311-other-lang-changes"></span><h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Permalink to this heading">¶</a></h2>
<ul class="simple">
<li><p>Starred unpacking expressions can now be used in <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a> statements.
(See <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46725">bpo-46725</a> for more details.)</p></li>
<li><p>Asynchronous <a class="reference internal" href="../reference/expressions.html#comprehensions"><span class="std std-ref">comprehensions</span></a> are now allowed
inside comprehensions in <a class="reference internal" href="../reference/compound_stmts.html#async-def"><span class="std std-ref">asynchronous functions</span></a>.
Outer comprehensions implicitly become asynchronous in this case.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33346">bpo-33346</a>.)</p></li>
<li><p>A <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is now raised instead of an <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> in
<a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statements and <a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack.enter_context" title="contextlib.ExitStack.enter_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.ExitStack.enter_context()</span></code></a>
for objects that do not support the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol,
and in <a class="reference internal" href="../reference/compound_stmts.html#async-with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code></a> statements and
<a class="reference internal" href="../library/contextlib.html#contextlib.AsyncExitStack.enter_async_context" title="contextlib.AsyncExitStack.enter_async_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.AsyncExitStack.enter_async_context()</span></code></a>
for objects not supporting the <a class="reference internal" href="../glossary.html#term-asynchronous-context-manager"><span class="xref std std-term">asynchronous context manager</span></a> protocol.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12022">bpo-12022</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44471">bpo-44471</a>.)</p></li>
<li><p>Added <a class="reference internal" href="../library/pickle.html#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getstate__()</span></code></a>, which provides the default
implementation of the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__getstate__()</span></code> method. <a class="reference internal" href="../library/copy.html#module-copy" title="copy: Shallow and deep copy operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">copy</span></code></a>ing
and <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a>ing instances of subclasses of builtin types
<a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#frozenset" title="frozenset"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozenset</span></code></a>,
<a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.OrderedDict</span></code></a>, <a class="reference internal" href="../library/collections.html#collections.deque" title="collections.deque"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.deque</span></code></a>,
<a class="reference internal" href="../library/weakref.html#weakref.WeakSet" title="weakref.WeakSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">weakref.WeakSet</span></code></a>, and <a class="reference internal" href="../library/datetime.html#datetime.tzinfo" title="datetime.tzinfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.tzinfo</span></code></a> now copies and
pickles instance attributes implemented as <a class="reference internal" href="../glossary.html#term-__slots__"><span class="xref std std-term">slots</span></a>.
This change has an unintended side effect: It trips up a small minority
of existing Python projects not expecting <a class="reference internal" href="../library/pickle.html#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getstate__()</span></code></a> to
exist. See the later comments on <a class="reference external" href="https://github.com/python/cpython/issues/70766">gh-70766</a> for discussions of what
workarounds such code may need.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26579">bpo-26579</a>.)</p></li>
</ul>
<ul class="simple" id="whatsnew311-pythonsafepath">
<li><p>Added a <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command line option
and a <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment variable,
which disable the automatic prepending to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>
of the script’s directory when running a script,
or the current directory when using <a class="reference internal" href="../using/cmdline.html#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> and <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a>.
This ensures only stdlib and installed modules
are picked up by <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a>,
and avoids unintentionally or maliciously shadowing modules
with those in a local (and typically user-writable) directory.
(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/57684">gh-57684</a>.)</p></li>
<li><p>A <code class="docutils literal notranslate"><span class="pre">"z"</span></code> option was added to the <a class="reference internal" href="../library/string.html#formatspec"><span class="std std-ref">Format Specification Mini-Language</span></a> that
coerces negative to positive zero after rounding to the format precision.
See <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0682/"><strong>PEP 682</strong></a> for more details.
(Contributed by John Belmonte in <a class="reference external" href="https://github.com/python/cpython/issues/90153">gh-90153</a>.)</p></li>
<li><p>Bytes are no longer accepted on <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>. Support broke sometime
between Python 3.2 and 3.6, with no one noticing until after Python 3.10.0
was released. In addition, bringing back support would be problematic due to
interactions between <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> when
there is a mixture of <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> keys.
(Contributed by Thomas Grainger in <a class="reference external" href="https://github.com/python/cpython/issues/91181">gh-91181</a>.)</p></li>
</ul>
</section>
<section id="other-cpython-implementation-changes">
<span id="whatsnew311-other-implementation-changes"></span><h2>Other CPython Implementation Changes<a class="headerlink" href="#other-cpython-implementation-changes" title="Permalink to this heading">¶</a></h2>
<ul class="simple">
<li><p>The special methods <a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__complex__()</span></code></a> for <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a>
and <a class="reference internal" href="../reference/datamodel.html#object.__bytes__" title="object.__bytes__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bytes__()</span></code></a> for <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> are implemented to support
the <a class="reference internal" href="../library/typing.html#typing.SupportsComplex" title="typing.SupportsComplex"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsComplex</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.SupportsBytes" title="typing.SupportsBytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsBytes</span></code></a> protocols.
(Contributed by Mark Dickinson and Dong-hee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24234">bpo-24234</a>.)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">siphash13</span></code> is added as a new internal hashing algorithm.
It has similar security properties as <code class="docutils literal notranslate"><span class="pre">siphash24</span></code>,
but it is slightly faster for long inputs.
<a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>, and some other types
now use it as the default algorithm for <a class="reference internal" href="../library/functions.html#hash" title="hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code></a>.
<span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0552/"><strong>PEP 552</strong></a> <a class="reference internal" href="../reference/import.html#pyc-invalidation"><span class="std std-ref">hash-based .pyc files</span></a>
now use <code class="docutils literal notranslate"><span class="pre">siphash13</span></code> too.
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29410">bpo-29410</a>.)</p></li>
<li><p>When an active exception is re-raised by a <a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">raise</span></code></a> statement with no parameters,
the traceback attached to this exception is now always <code class="docutils literal notranslate"><span class="pre">sys.exc_info()[1].__traceback__</span></code>.
This means that changes made to the traceback in the current <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> clause are
reflected in the re-raised exception.
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
<li><p>The interpreter state’s representation of handled exceptions
(aka <code class="docutils literal notranslate"><span class="pre">exc_info</span></code> or <code class="docutils literal notranslate"><span class="pre">_PyErr_StackItem</span></code>)
now only has the <code class="docutils literal notranslate"><span class="pre">exc_value</span></code> field; <code class="docutils literal notranslate"><span class="pre">exc_type</span></code> and <code class="docutils literal notranslate"><span class="pre">exc_traceback</span></code>
have been removed, as they can be derived from <code class="docutils literal notranslate"><span class="pre">exc_value</span></code>.
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
<li><p>A new <a class="reference internal" href="../using/windows.html#install-quiet-option"><span class="std std-ref">command line option</span></a>, <code class="docutils literal notranslate"><span class="pre">AppendPath</span></code>,
has been added for the Windows installer.
It behaves similarly to <code class="docutils literal notranslate"><span class="pre">PrependPath</span></code>,
but appends the install and scripts directories instead of prepending them.
(Contributed by Bastian Neuburger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44934">bpo-44934</a>.)</p></li>
<li><p>The <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths_set</span></code></a> field must now be set to <code class="docutils literal notranslate"><span class="pre">1</span></code> for
initialization to use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a> to initialize
<a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>. Otherwise, initialization will recalculate the path and replace
any values added to <code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code>.</p></li>
<li><p>The output of the <a class="reference internal" href="../using/cmdline.html#cmdoption-help"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help</span></code></a> option now fits in 50 lines/80 columns.
Information about <a class="reference internal" href="../using/cmdline.html#using-on-envvars"><span class="std std-ref">Python environment variables</span></a>
and <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> options is now available using the respective
<a class="reference internal" href="../using/cmdline.html#cmdoption-help-env"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-env</span></code></a> and <a class="reference internal" href="../using/cmdline.html#cmdoption-help-xoptions"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-xoptions</span></code></a> flags,
and with the new <a class="reference internal" href="../using/cmdline.html#cmdoption-help-all"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-all</span></code></a>.
(Contributed by Éric Araujo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46142">bpo-46142</a>.)</p></li>
<li><p>Converting between <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> in bases other than 2
(binary), 4, 8 (octal), 16 (hexadecimal), or 32 such as base 10 (decimal)
now raises a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if the number of digits in string form is
above a limit to avoid potential denial of service attacks due to the
algorithmic complexity. This is a mitigation for <a class="reference external" href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-10735">CVE-2020-10735</a>.
This limit can be configured or disabled by environment variable, command
line flag, or <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> APIs. See the <a class="reference internal" href="../library/stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion
length limitation</span></a> documentation. The default limit
is 4300 digits in string form.</p></li>
</ul>
</section>
<section id="new-modules">
<span id="whatsnew311-new-modules"></span><h2>New Modules<a class="headerlink" href="#new-modules" title="Permalink to this heading">¶</a></h2>
<ul class="simple">
<li><p><a class="reference internal" href="../library/tomllib.html#module-tomllib" title="tomllib: Parse TOML files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code></a>: For parsing <a class="reference external" href="https://toml.io/">TOML</a>.
See <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0680/"><strong>PEP 680</strong></a> for more details.
(Contributed by Taneli Hukkinen in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40059">bpo-40059</a>.)</p></li>
<li><p><a class="reference internal" href="../library/wsgiref.html#module-wsgiref.types" title="wsgiref.types: WSGI types for static type checking"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.types</span></code></a>:
<span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>WSGI</strong></a>-specific types for static type checking.
(Contributed by Sebastian Rittau in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=42012">bpo-42012</a>.)</p></li>
</ul>
</section>
<section id="improved-modules">
<span id="whatsnew311-improved-modules"></span><h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Permalink to this heading">¶</a></h2>
<section id="asyncio">
<span id="whatsnew311-asyncio"></span><h3>asyncio<a class="headerlink" href="#asyncio" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Added the <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a> class,
an <a class="reference internal" href="../reference/datamodel.html#async-context-managers"><span class="std std-ref">asynchronous context manager</span></a>
holding a group of tasks that will wait for all of them upon exit.
For new code this is recommended over using
<a class="reference internal" href="../library/asyncio-task.html#asyncio.create_task" title="asyncio.create_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_task()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.gather" title="asyncio.gather"><code class="xref py py-func docutils literal notranslate"><span class="pre">gather()</span></code></a> directly.
(Contributed by Yury Selivanov and others in <a class="reference external" href="https://github.com/python/cpython/issues/90908">gh-90908</a>.)</p></li>
<li><p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.timeout" title="asyncio.timeout"><code class="xref py py-func docutils literal notranslate"><span class="pre">timeout()</span></code></a>, an asynchronous context manager for
setting a timeout on asynchronous operations. For new code this is
recommended over using <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait_for()</span></code></a> directly.
(Contributed by Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/90927">gh-90927</a>.)</p></li>
<li><p>Added the <a class="reference internal" href="../library/asyncio-runner.html#asyncio.Runner" title="asyncio.Runner"><code class="xref py py-class docutils literal notranslate"><span class="pre">Runner</span></code></a> class, which exposes the machinery
used by <a class="reference internal" href="../library/asyncio-runner.html#asyncio.run" title="asyncio.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">run()</span></code></a>.
(Contributed by Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/91218">gh-91218</a>.)</p></li>
<li><p>Added the <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Barrier" title="asyncio.Barrier"><code class="xref py py-class docutils literal notranslate"><span class="pre">Barrier</span></code></a> class to the synchronization
primitives in the asyncio library, and the related
<a class="reference internal" href="../library/asyncio-sync.html#asyncio.BrokenBarrierError" title="asyncio.BrokenBarrierError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenBarrierError</span></code></a> exception.
(Contributed by Yves Duprat and Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/87518">gh-87518</a>.)</p></li>
<li><p>Added keyword argument <em>all_errors</em> to <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_connection()</span></code></a>
so that multiple connection errors can be raised as an <a class="reference internal" href="../library/exceptions.html#ExceptionGroup" title="ExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExceptionGroup</span></code></a>.</p></li>
<li><p>Added the <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamWriter.start_tls" title="asyncio.StreamWriter.start_tls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.StreamWriter.start_tls()</span></code></a> method for
upgrading existing stream-based connections to TLS.
(Contributed by Ian Good in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34975">bpo-34975</a>.)</p></li>
<li><p>Added raw datagram socket functions to the event loop:
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_sendto" title="asyncio.loop.sock_sendto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_sendto()</span></code></a>,
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recvfrom" title="asyncio.loop.sock_recvfrom"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_recvfrom()</span></code></a> and
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recvfrom_into" title="asyncio.loop.sock_recvfrom_into"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_recvfrom_into()</span></code></a>.
These have implementations in <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.SelectorEventLoop" title="asyncio.SelectorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectorEventLoop</span></code></a> and
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a>.
(Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46805">bpo-46805</a>.)</p></li>
<li><p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.cancelling" title="asyncio.Task.cancelling"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cancelling()</span></code></a> and
<a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.uncancel" title="asyncio.Task.uncancel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">uncancel()</span></code></a> methods to <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a>.
These are primarily intended for internal use,
notably by <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a>.</p></li>
</ul>
</section>
<section id="contextlib">
<span id="whatsnew311-contextlib"></span><h3>contextlib<a class="headerlink" href="#contextlib" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Added non parallel-safe <a class="reference internal" href="../library/contextlib.html#contextlib.chdir" title="contextlib.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a> context manager to change
the current working directory and then restore it on exit. Simple wrapper
around <a class="reference internal" href="../library/os.html#os.chdir" title="os.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a>. (Contributed by Filipe Laíns in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25625">bpo-25625</a>)</p></li>
</ul>
</section>
<section id="dataclasses">
<span id="whatsnew311-dataclasses"></span><h3>dataclasses<a class="headerlink" href="#dataclasses" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Change field default mutability check, allowing only defaults which are
<a class="reference internal" href="../glossary.html#term-hashable"><span class="xref std std-term">hashable</span></a> instead of any object which is not an instance of
<a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> or <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>. (Contributed by Eric V. Smith in
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44674">bpo-44674</a>.)</p></li>
</ul>
</section>
<section id="datetime">
<span id="whatsnew311-datetime"></span><h3>datetime<a class="headerlink" href="#datetime" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Add <a class="reference internal" href="../library/datetime.html#datetime.UTC" title="datetime.UTC"><code class="xref py py-const docutils literal notranslate"><span class="pre">datetime.UTC</span></code></a>, a convenience alias for
<a class="reference internal" href="../library/datetime.html#datetime.timezone.utc" title="datetime.timezone.utc"><code class="xref py py-attr docutils literal notranslate"><span class="pre">datetime.timezone.utc</span></code></a>. (Contributed by Kabir Kwatra in <a class="reference external" href="https://github.com/python/cpython/issues/91973">gh-91973</a>.)</p></li>
<li><p><a class="reference internal" href="../library/datetime.html#datetime.date.fromisoformat" title="datetime.date.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.date.fromisoformat()</span></code></a>, <a class="reference internal" href="../library/datetime.html#datetime.time.fromisoformat" title="datetime.time.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.time.fromisoformat()</span></code></a> and
<a class="reference internal" href="../library/datetime.html#datetime.datetime.fromisoformat" title="datetime.datetime.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.fromisoformat()</span></code></a> can now be used to parse most ISO 8601
formats (barring only those that support fractional hours and minutes).
(Contributed by Paul Ganssle in <a class="reference external" href="https://github.com/python/cpython/issues/80010">gh-80010</a>.)</p></li>
</ul>
</section>
<section id="enum">
<span id="whatsnew311-enum"></span><h3>enum<a class="headerlink" href="#enum" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Renamed <code class="xref py py-class docutils literal notranslate"><span class="pre">EnumMeta</span></code> to <a class="reference internal" href="../library/enum.html#enum.EnumType" title="enum.EnumType"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnumType</span></code></a>
(<code class="xref py py-class docutils literal notranslate"><span class="pre">EnumMeta</span></code> kept as an alias).</p></li>
<li><p>Added <a class="reference internal" href="../library/enum.html#enum.StrEnum" title="enum.StrEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">StrEnum</span></code></a>,
with members that can be used as (and must be) strings.</p></li>
<li><p>Added <a class="reference internal" href="../library/enum.html#enum.ReprEnum" title="enum.ReprEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">ReprEnum</span></code></a>,
which only modifies the <a class="reference internal" href="../reference/datamodel.html#object.__repr__" title="object.__repr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__repr__()</span></code></a> of members
while returning their literal values (rather than names)
for <a class="reference internal" href="../reference/datamodel.html#object.__str__" title="object.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__str__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__format__" title="object.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__format__()</span></code></a>
(used by <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a>, <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> and <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s).</p></li>
<li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Enum.__format__" title="enum.Enum.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Enum.__format__()</span></code></a> (the default for
<a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> and <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s) to always produce
the same result as <code class="xref py py-meth docutils literal notranslate"><span class="pre">Enum.__str__()</span></code>: for enums inheriting from
<a class="reference internal" href="../library/enum.html#enum.ReprEnum" title="enum.ReprEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">ReprEnum</span></code></a> it will be the member’s value; for all other enums
it will be the enum and member name (e.g. <code class="docutils literal notranslate"><span class="pre">Color.RED</span></code>).</p></li>
<li><p>Added a new <em>boundary</em> class parameter to <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> enums
and the <a class="reference internal" href="../library/enum.html#enum.FlagBoundary" title="enum.FlagBoundary"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlagBoundary</span></code></a> enum with its options,
to control how to handle out-of-range flag values.</p></li>
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.verify" title="enum.verify"><code class="xref py py-func docutils literal notranslate"><span class="pre">verify()</span></code></a> enum decorator
and the <a class="reference internal" href="../library/enum.html#enum.EnumCheck" title="enum.EnumCheck"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnumCheck</span></code></a> enum with its options,
to check enum classes against several specific constraints.</p></li>
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.member" title="enum.member"><code class="xref py py-func docutils literal notranslate"><span class="pre">member()</span></code></a> and <a class="reference internal" href="../library/enum.html#enum.nonmember" title="enum.nonmember"><code class="xref py py-func docutils literal notranslate"><span class="pre">nonmember()</span></code></a> decorators,
to ensure the decorated object is/is not converted to an enum member.</p></li>
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.property" title="enum.property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a> decorator,
which works like <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a> except for enums.
Use this instead of <a class="reference internal" href="../library/types.html#types.DynamicClassAttribute" title="types.DynamicClassAttribute"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.DynamicClassAttribute()</span></code></a>.</p></li>
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.global_enum" title="enum.global_enum"><code class="xref py py-func docutils literal notranslate"><span class="pre">global_enum()</span></code></a> enum decorator,
which adjusts <a class="reference internal" href="../reference/datamodel.html#object.__repr__" title="object.__repr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__repr__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__str__" title="object.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__str__()</span></code></a>
to show values as members of their module rather than the enum class.
For example, <code class="docutils literal notranslate"><span class="pre">'re.ASCII'</span></code> for the <a class="reference internal" href="../library/re.html#re.ASCII" title="re.ASCII"><code class="xref py py-const docutils literal notranslate"><span class="pre">ASCII</span></code></a> member
of <a class="reference internal" href="../library/re.html#re.RegexFlag" title="re.RegexFlag"><code class="xref py py-class docutils literal notranslate"><span class="pre">re.RegexFlag</span></code></a> rather than <code class="docutils literal notranslate"><span class="pre">'RegexFlag.ASCII'</span></code>.</p></li>
<li><p>Enhanced <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> to support
<a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a>, iteration and <a class="reference internal" href="../reference/expressions.html#in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">in</span></code></a>/<a class="reference internal" href="../reference/expressions.html#not-in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">not</span> <span class="pre">in</span></code></a> on its members.
For example, the following now works:
<code class="docutils literal notranslate"><span class="pre">len(AFlag(3))</span> <span class="pre">==</span> <span class="pre">2</span> <span class="pre">and</span> <span class="pre">list(AFlag(3))</span> <span class="pre">==</span> <span class="pre">(AFlag.ONE,</span> <span class="pre">AFlag.TWO)</span></code></p></li>
<li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Enum" title="enum.Enum"><code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code></a> and <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a>
so that members are now defined
before <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init_subclass__()</span></code></a> is called;
<a class="reference internal" href="../library/functions.html#dir" title="dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code></a> now includes methods, etc., from mixed-in data types.</p></li>
<li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a>
to only consider primary values (power of two) canonical
while composite values (<code class="docutils literal notranslate"><span class="pre">3</span></code>, <code class="docutils literal notranslate"><span class="pre">6</span></code>, <code class="docutils literal notranslate"><span class="pre">10</span></code>, etc.) are considered aliases;
inverted flags are coerced to their positive equivalent.</p></li>
</ul>
</section>
<section id="fcntl">
<span id="whatsnew311-fcntl"></span><h3>fcntl<a class="headerlink" href="#fcntl" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>On FreeBSD, the <code class="xref py py-data docutils literal notranslate"><span class="pre">F_DUP2FD</span></code> and <code class="xref py py-data docutils literal notranslate"><span class="pre">F_DUP2FD_CLOEXEC</span></code> flags respectively
are supported, the former equals to <code class="docutils literal notranslate"><span class="pre">dup2</span></code> usage while the latter set
the <code class="docutils literal notranslate"><span class="pre">FD_CLOEXEC</span></code> flag in addition.</p></li>
</ul>
</section>
<section id="fractions">
<span id="whatsnew311-fractions"></span><h3>fractions<a class="headerlink" href="#fractions" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Support <span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0515/"><strong>PEP 515</strong></a>-style initialization of <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> from
string. (Contributed by Sergey B Kirpichev in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44258">bpo-44258</a>.)</p></li>
<li><p><a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> now implements an <code class="docutils literal notranslate"><span class="pre">__int__</span></code> method, so
that an <code class="docutils literal notranslate"><span class="pre">isinstance(some_fraction,</span> <span class="pre">typing.SupportsInt)</span></code> check passes.
(Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44547">bpo-44547</a>.)</p></li>
</ul>
</section>
<section id="functools">
<span id="whatsnew311-functools"></span><h3>functools<a class="headerlink" href="#functools" title="Permalink to this heading">¶</a></h3>
<ul>
<li><p><a class="reference internal" href="../library/functools.html#functools.singledispatch" title="functools.singledispatch"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.singledispatch()</span></code></a> now supports <a class="reference internal" href="../library/types.html#types.UnionType" title="types.UnionType"><code class="xref py py-data docutils literal notranslate"><span class="pre">types.UnionType</span></code></a>
and <a class="reference internal" href="../library/typing.html#typing.Union" title="typing.Union"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Union</span></code></a> as annotations to the dispatch argument.:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">singledispatch</span>
<span class="gp">>>> </span><span class="nd">@singledispatch</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">fun</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Let me just say,"</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">" "</span><span class="p">)</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="nd">@fun</span><span class="o">.</span><span class="n">register</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">_</span><span class="p">(</span><span class="n">arg</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">float</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Strength in numbers, eh?"</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">" "</span><span class="p">)</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Union</span>
<span class="gp">>>> </span><span class="nd">@fun</span><span class="o">.</span><span class="n">register</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">_</span><span class="p">(</span><span class="n">arg</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">],</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Enumerate this:"</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">elem</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">elem</span><span class="p">)</span>
<span class="gp">...</span>
</pre></div>
</div>
<p>(Contributed by Yurii Karabas in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46014">bpo-46014</a>.)</p>
</li>
</ul>
</section>
<section id="hashlib">
<span id="whatsnew311-hashlib"></span><h3>hashlib<a class="headerlink" href="#hashlib" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p><a class="reference internal" href="../library/hashlib.html#hashlib.blake2b" title="hashlib.blake2b"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.blake2b()</span></code></a> and <a class="reference internal" href="../library/hashlib.html#hashlib.blake2s" title="hashlib.blake2s"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.blake2s()</span></code></a> now prefer <a class="reference external" href="https://www.blake2.net/">libb2</a>
over Python’s vendored copy.
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47095">bpo-47095</a>.)</p></li>
<li><p>The internal <code class="docutils literal notranslate"><span class="pre">_sha3</span></code> module with SHA3 and SHAKE algorithms now uses
<em>tiny_sha3</em> instead of the <em>Keccak Code Package</em> to reduce code and binary
size. The <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> module prefers optimized SHA3 and SHAKE
implementations from OpenSSL. The change affects only installations without
OpenSSL support.
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47098">bpo-47098</a>.)</p></li>
<li><p>Add <a class="reference internal" href="../library/hashlib.html#hashlib.file_digest" title="hashlib.file_digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.file_digest()</span></code></a>, a helper function for efficient hashing
of files or file-like objects.
(Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/89313">gh-89313</a>.)</p></li>
</ul>
</section>
<section id="whatsnew311-idle">
<span id="idle-and-idlelib"></span><h3>IDLE and idlelib<a class="headerlink" href="#whatsnew311-idle" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Apply syntax highlighting to <code class="docutils literal notranslate"><span class="pre">.pyi</span></code> files. (Contributed by Alex
Waygood and Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45447">bpo-45447</a>.)</p></li>
<li><p>Include prompts when saving Shell with inputs and outputs.
(Contributed by Terry Jan Reedy in <a class="reference external" href="https://github.com/python/cpython/issues/95191">gh-95191</a>.)</p></li>
</ul>
</section>
<section id="inspect">
<span id="whatsnew311-inspect"></span><h3>inspect<a class="headerlink" href="#inspect" title="Permalink to this heading">¶</a></h3>
<ul>
<li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.getmembers_static" title="inspect.getmembers_static"><code class="xref py py-func docutils literal notranslate"><span class="pre">getmembers_static()</span></code></a> to return all members without
triggering dynamic lookup via the descriptor protocol. (Contributed by
Weipeng Hong in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30533">bpo-30533</a>.)</p></li>
<li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.ismethodwrapper" title="inspect.ismethodwrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">ismethodwrapper()</span></code></a>
for checking if the type of an object is a <a class="reference internal" href="../library/types.html#types.MethodWrapperType" title="types.MethodWrapperType"><code class="xref py py-class docutils literal notranslate"><span class="pre">MethodWrapperType</span></code></a>.
(Contributed by Hakan Çelik in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29418">bpo-29418</a>.)</p></li>
<li><p>Change the frame-related functions in the <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> module to return new
<a class="reference internal" href="../library/inspect.html#inspect.FrameInfo" title="inspect.FrameInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">FrameInfo</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.Traceback" title="inspect.Traceback"><code class="xref py py-class docutils literal notranslate"><span class="pre">Traceback</span></code></a> class instances
(backwards compatible with the previous <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a>-like interfaces)
that includes the extended <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0657/"><strong>PEP 657</strong></a> position information (end
line number, column and end column). The affected functions are:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/inspect.html#inspect.getframeinfo" title="inspect.getframeinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getframeinfo()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/inspect.html#inspect.getouterframes" title="inspect.getouterframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getouterframes()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/inspect.html#inspect.getinnerframes" title="inspect.getinnerframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getinnerframes()</span></code></a>,</p></li>
<li><p><a class="reference internal" href="../library/inspect.html#inspect.stack" title="inspect.stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.stack()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/inspect.html#inspect.trace" title="inspect.trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.trace()</span></code></a></p></li>
</ul>
<p>(Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/88116">gh-88116</a>.)</p>
</li>
</ul>
</section>
<section id="locale">
<span id="whatsnew311-locale"></span><h3>locale<a class="headerlink" href="#locale" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Add <a class="reference internal" href="../library/locale.html#locale.getencoding" title="locale.getencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getencoding()</span></code></a> to get the current locale encoding. It is similar to
<code class="docutils literal notranslate"><span class="pre">locale.getpreferredencoding(False)</span></code> but ignores the
<a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>.</p></li>
</ul>
</section>
<section id="logging">
<span id="whatsnew311-logging"></span><h3>logging<a class="headerlink" href="#logging" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Added <a class="reference internal" href="../library/logging.html#logging.getLevelNamesMapping" title="logging.getLevelNamesMapping"><code class="xref py py-func docutils literal notranslate"><span class="pre">getLevelNamesMapping()</span></code></a>
to return a mapping from logging level names (e.g. <code class="docutils literal notranslate"><span class="pre">'CRITICAL'</span></code>)
to the values of their corresponding <a class="reference internal" href="../library/logging.html#levels"><span class="std std-ref">Logging Levels</span></a> (e.g. <code class="docutils literal notranslate"><span class="pre">50</span></code>, by default).
(Contributed by Andrei Kulakovin in <a class="reference external" href="https://github.com/python/cpython/issues/88024">gh-88024</a>.)</p></li>
<li><p>Added a <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler.createSocket" title="logging.handlers.SysLogHandler.createSocket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createSocket()</span></code></a> method
to <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a>, to match
<a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SocketHandler.createSocket" title="logging.handlers.SocketHandler.createSocket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SocketHandler.createSocket()</span></code></a>.
It is called automatically during handler initialization
and when emitting an event, if there is no active socket.
(Contributed by Kirill Pinchuk in <a class="reference external" href="https://github.com/python/cpython/issues/88457">gh-88457</a>.)</p></li>
</ul>
</section>
<section id="math">
<span id="whatsnew311-math"></span><h3>math<a class="headerlink" href="#math" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Add <a class="reference internal" href="../library/math.html#math.exp2" title="math.exp2"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.exp2()</span></code></a>: return 2 raised to the power of x.
(Contributed by Gideon Mitchell in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45917">bpo-45917</a>.)</p></li>
<li><p>Add <a class="reference internal" href="../library/math.html#math.cbrt" title="math.cbrt"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.cbrt()</span></code></a>: return the cube root of x.
(Contributed by Ajith Ramachandran in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44357">bpo-44357</a>.)</p></li>
<li><p>The behaviour of two <a class="reference internal" href="../library/math.html#math.pow" title="math.pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.pow()</span></code></a> corner cases was changed, for
consistency with the IEEE 754 specification. The operations
<code class="docutils literal notranslate"><span class="pre">math.pow(0.0,</span> <span class="pre">-math.inf)</span></code> and <code class="docutils literal notranslate"><span class="pre">math.pow(-0.0,</span> <span class="pre">-math.inf)</span></code> now return
<code class="docutils literal notranslate"><span class="pre">inf</span></code>. Previously they raised <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>. (Contributed by Mark
Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44339">bpo-44339</a>.)</p></li>
<li><p>The <a class="reference internal" href="../library/math.html#math.nan" title="math.nan"><code class="xref py py-data docutils literal notranslate"><span class="pre">math.nan</span></code></a> value is now always available.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46917">bpo-46917</a>.)</p></li>
</ul>
</section>
<section id="operator">
<span id="whatsnew311-operator"></span><h3>operator<a class="headerlink" href="#operator" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>A new function <code class="docutils literal notranslate"><span class="pre">operator.call</span></code> has been added, such that
<code class="docutils literal notranslate"><span class="pre">operator.call(obj,</span> <span class="pre">*args,</span> <span class="pre">**kwargs)</span> <span class="pre">==</span> <span class="pre">obj(*args,</span> <span class="pre">**kwargs)</span></code>.
(Contributed by Antony Lee in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44019">bpo-44019</a>.)</p></li>
</ul>
</section>
<section id="os">
<span id="whatsnew311-os"></span><h3>os<a class="headerlink" href="#os" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>On Windows, <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> now uses <code class="docutils literal notranslate"><span class="pre">BCryptGenRandom()</span></code>,
instead of <code class="docutils literal notranslate"><span class="pre">CryptGenRandom()</span></code> which is deprecated.
(Contributed by Dong-hee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44611">bpo-44611</a>.)</p></li>
</ul>