Spaces:
Running on Zero
Running on Zero
File size: 124,345 Bytes
9273228 | 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 | # What\'s New In Python 3.7
Editor
: Elvis Pranskevichus \<elvis@magic.io\>
> \* Anyone can add text to this document. Do not spend very much time on the wording of your changes, because your text will probably get rewritten to some degree.
>
> \* The maintainer will go through Misc/NEWS periodically and add changes; it\'s therefore more important to add your changes to Misc/NEWS than to this file.
>
> \* This is not a complete list of every single change; completeness is the purpose of Misc/NEWS. Some changes I consider too small or esoteric to include. If such a change is added to the text, I\'ll just remove it. (This is another reason you shouldn\'t spend too much time on writing your addition.)
>
> \* If you want to draw your new text to the attention of the maintainer, add \'XXX\' to the beginning of the paragraph or section.
>
> \* It\'s OK to just add a fragmentary note about a change. For example: \"XXX Describe the transmogrify() function added to the socket module.\" The maintainer will research the change and write the necessary text.
>
> \* You can comment out your additions if you like, but it\'s not necessary (especially when a final release is some months away).
>
> \* Credit the author of a patch or bugfix. Just the name is sufficient; the e-mail address isn\'t necessary.
>
> - It\'s helpful to add the bug/patch number as a comment:
>
> XXX Describe the transmogrify() function added to the socket module. (Contributed by P.Y. Developer in `12345`{.interpreted-text role="issue"}.)
>
> This saves the maintainer the effort of going through the Git log when researching a change.
This article explains the new features in Python 3.7, compared to 3.6. Python 3.7 was released on June 27, 2018. For full details, see the `changelog <changelog>`{.interpreted-text role="ref"}.
## Summary \-- Release Highlights
New syntax features:
- `PEP 563 <whatsnew37-pep563>`{.interpreted-text role="ref"}, postponed evaluation of type annotations.
Backwards incompatible syntax changes:
- `async`{.interpreted-text role="keyword"} and `await`{.interpreted-text role="keyword"} are now reserved keywords.
New library modules:
- `contextvars`{.interpreted-text role="mod"}: `PEP 567 -- Context Variables <whatsnew37-pep567>`{.interpreted-text role="ref"}
- `dataclasses`{.interpreted-text role="mod"}: `PEP 557 -- Data Classes <whatsnew37-pep557>`{.interpreted-text role="ref"}
- `whatsnew37_importlib_resources`{.interpreted-text role="ref"}
New built-in features:
- `PEP 553 <whatsnew37-pep553>`{.interpreted-text role="ref"}, the new `breakpoint`{.interpreted-text role="func"} function.
Python data model improvements:
- `PEP 562 <whatsnew37-pep562>`{.interpreted-text role="ref"}, customization of access to module attributes.
- `PEP 560 <whatsnew37-pep560>`{.interpreted-text role="ref"}, core support for typing module and generic types.
- the insertion-order preservation nature of `dict <typesmapping>`{.interpreted-text role="ref"} objects [has been declared](https://mail.python.org/pipermail/python-dev/2017-December/151283.html) to be an official part of the Python language spec.
Significant improvements in the standard library:
- The `asyncio`{.interpreted-text role="mod"} module has received new features, significant `usability and performance improvements <whatsnew37_asyncio>`{.interpreted-text role="ref"}.
- The `time`{.interpreted-text role="mod"} module gained support for `functions with nanosecond resolution <whatsnew37-pep564>`{.interpreted-text role="ref"}.
CPython implementation improvements:
- Avoiding the use of ASCII as a default text encoding:
- `PEP 538 <whatsnew37-pep538>`{.interpreted-text role="ref"}, legacy C locale coercion
- `PEP 540 <whatsnew37-pep540>`{.interpreted-text role="ref"}, forced UTF-8 runtime mode
- `PEP 552 <whatsnew37-pep552>`{.interpreted-text role="ref"}, deterministic .pycs
- `New Python Development Mode <whatsnew37-devmode>`{.interpreted-text role="ref"}
- `PEP 565 <whatsnew37-pep565>`{.interpreted-text role="ref"}, improved `DeprecationWarning`{.interpreted-text role="exc"} handling
C API improvements:
- `PEP 539 <whatsnew37-pep539>`{.interpreted-text role="ref"}, new C API for thread-local storage
Documentation improvements:
- `PEP 545 <whatsnew37-pep545>`{.interpreted-text role="ref"}, Python documentation translations
- New documentation translations: [Japanese](https://docs.python.org/ja/), [French](https://docs.python.org/fr/), and [Korean](https://docs.python.org/ko/).
This release features notable performance improvements in many areas. The `whatsnew37-perf`{.interpreted-text role="ref"} section lists them in detail.
For a list of changes that may affect compatibility with previous Python releases please refer to the `porting-to-python-37`{.interpreted-text role="ref"} section.
## New Features
### PEP 563: Postponed Evaluation of Annotations {#whatsnew37-pep563}
The advent of type hints in Python uncovered two glaring usability issues with the functionality of annotations added in `3107`{.interpreted-text role="pep"} and refined further in `526`{.interpreted-text role="pep"}:
- annotations could only use names which were already available in the current scope, in other words they didn\'t support forward references of any kind; and
- annotating source code had adverse effects on startup time of Python programs.
Both of these issues are fixed by postponing the evaluation of annotations. Instead of compiling code which executes expressions in annotations at their definition time, the compiler stores the annotation in a string form equivalent to the AST of the expression in question. If needed, annotations can be resolved at runtime using `typing.get_type_hints`{.interpreted-text role="func"}. In the common case where this is not required, the annotations are cheaper to store (since short strings are interned by the interpreter) and make startup time faster.
Usability-wise, annotations now support forward references, making the following syntax valid:
class C:
@classmethod
def from_string(cls, source: str) -> C:
...
def validate_b(self, obj: B) -> bool:
...
class B:
...
Since this change breaks compatibility, the new behavior needs to be enabled on a per-module basis in Python 3.7 using a `__future__`{.interpreted-text role="mod"} import:
from __future__ import annotations
It will become the default in Python 3.10.
::: seealso
`563`{.interpreted-text role="pep"} \-- Postponed evaluation of annotations
: PEP written and implemented by Łukasz Langa.
:::
### PEP 538: Legacy C Locale Coercion {#whatsnew37-pep538}
An ongoing challenge within the Python 3 series has been determining a sensible default strategy for handling the \"7-bit ASCII\" text encoding assumption currently implied by the use of the default C or POSIX locale on non-Windows platforms.
`538`{.interpreted-text role="pep"} updates the default interpreter command line interface to automatically coerce that locale to an available UTF-8 based locale as described in the documentation of the new `PYTHONCOERCECLOCALE`{.interpreted-text role="envvar"} environment variable. Automatically setting `LC_CTYPE` this way means that both the core interpreter and locale-aware C extensions (such as `readline`{.interpreted-text role="mod"}) will assume the use of UTF-8 as the default text encoding, rather than ASCII.
The platform support definition in `11`{.interpreted-text role="pep"} has also been updated to limit full text handling support to suitably configured non-ASCII based locales.
As part of this change, the default error handler for `~sys.stdin`{.interpreted-text role="data"} and `~sys.stdout`{.interpreted-text role="data"} is now `surrogateescape` (rather than `strict`) when using any of the defined coercion target locales (currently `C.UTF-8`, `C.utf8`, and `UTF-8`). The default error handler for `~sys.stderr`{.interpreted-text role="data"} continues to be `backslashreplace`, regardless of locale.
Locale coercion is silent by default, but to assist in debugging potentially locale related integration problems, explicit warnings (emitted directly on `~sys.stderr`{.interpreted-text role="data"}) can be requested by setting `PYTHONCOERCECLOCALE=warn`. This setting will also cause the Python runtime to emit a warning if the legacy C locale remains active when the core interpreter is initialized.
While `538`{.interpreted-text role="pep"}\'s locale coercion has the benefit of also affecting extension modules (such as GNU `readline`), as well as child processes (including those running non-Python applications and older versions of Python), it has the downside of requiring that a suitable target locale be present on the running system. To better handle the case where no suitable target locale is available (as occurs on RHEL/CentOS 7, for example), Python 3.7 also implements `whatsnew37-pep540`{.interpreted-text role="ref"}.
::: seealso
`538`{.interpreted-text role="pep"} \-- Coercing the legacy C locale to a UTF-8 based locale
: PEP written and implemented by Nick Coghlan.
:::
### PEP 540: Forced UTF-8 Runtime Mode {#whatsnew37-pep540}
The new `-X`{.interpreted-text role="option"} `utf8` command line option and `PYTHONUTF8`{.interpreted-text role="envvar"} environment variable can be used to enable the `Python UTF-8 Mode
<utf8-mode>`{.interpreted-text role="ref"}.
When in UTF-8 mode, CPython ignores the locale settings, and uses the UTF-8 encoding by default. The error handlers for `sys.stdin`{.interpreted-text role="data"} and `sys.stdout`{.interpreted-text role="data"} streams are set to `surrogateescape`.
The forced UTF-8 mode can be used to change the text handling behavior in an embedded Python interpreter without changing the locale settings of an embedding application.
While `540`{.interpreted-text role="pep"}\'s UTF-8 mode has the benefit of working regardless of which locales are available on the running system, it has the downside of having no effect on extension modules (such as GNU `readline`), child processes running non-Python applications, and child processes running older versions of Python. To reduce the risk of corrupting text data when communicating with such components, Python 3.7 also implements `whatsnew37-pep540`{.interpreted-text role="ref"}).
The UTF-8 mode is enabled by default when the locale is `C` or `POSIX`, and the `538`{.interpreted-text role="pep"} locale coercion feature fails to change it to a UTF-8 based alternative (whether that failure is due to `PYTHONCOERCECLOCALE=0` being set, `LC_ALL` being set, or the lack of a suitable target locale).
::: seealso
`540`{.interpreted-text role="pep"} \-- Add a new UTF-8 mode
: PEP written and implemented by Victor Stinner
:::
### PEP 553: Built-in `breakpoint()` {#whatsnew37-pep553}
Python 3.7 includes the new built-in `breakpoint`{.interpreted-text role="func"} function as an easy and consistent way to enter the Python debugger.
Built-in `breakpoint()` calls `sys.breakpointhook`{.interpreted-text role="func"}. By default, the latter imports `pdb`{.interpreted-text role="mod"} and then calls `pdb.set_trace()`, but by binding `sys.breakpointhook()` to the function of your choosing, `breakpoint()` can enter any debugger. Additionally, the environment variable `PYTHONBREAKPOINT`{.interpreted-text role="envvar"} can be set to the callable of your debugger of choice. Set `PYTHONBREAKPOINT=0` to completely disable built-in `breakpoint()`.
::: seealso
`553`{.interpreted-text role="pep"} \-- Built-in breakpoint()
: PEP written and implemented by Barry Warsaw
:::
### PEP 539: New C API for Thread-Local Storage {#whatsnew37-pep539}
While Python provides a C API for thread-local storage support; the existing `Thread Local Storage (TLS) API <thread-local-storage-api>`{.interpreted-text role="ref"} has used `int`{.interpreted-text role="c:expr"} to represent TLS keys across all platforms. This has not generally been a problem for officially support platforms, but that is neither POSIX-compliant, nor portable in any practical sense.
`539`{.interpreted-text role="pep"} changes this by providing a new `Thread Specific Storage (TSS)
API <thread-specific-storage-api>`{.interpreted-text role="ref"} to CPython which supersedes use of the existing TLS API within the CPython interpreter, while deprecating the existing API. The TSS API uses a new type `Py_tss_t`{.interpreted-text role="c:type"} instead of `int`{.interpreted-text role="c:expr"} to represent TSS keys\--an opaque type the definition of which may depend on the underlying TLS implementation. Therefore, this will allow to build CPython on platforms where the native TLS key is defined in a way that cannot be safely cast to `int`{.interpreted-text role="c:expr"}.
Note that on platforms where the native TLS key is defined in a way that cannot be safely cast to `int`{.interpreted-text role="c:expr"}, all functions of the existing TLS API will be no-op and immediately return failure. This indicates clearly that the old API is not supported on platforms where it cannot be used reliably, and that no effort will be made to add such support.
::: seealso
`539`{.interpreted-text role="pep"} \-- A New C-API for Thread-Local Storage in CPython
: PEP written by Erik M. Bray; implementation by Masayuki Yamamoto.
:::
### PEP 562: Customization of Access to Module Attributes {#whatsnew37-pep562}
Python 3.7 allows defining `~module.__getattr__`{.interpreted-text role="meth"} on modules and will call it whenever a module attribute is otherwise not found. Defining `~module.__dir__`{.interpreted-text role="meth"} on modules is now also allowed.
A typical example of where this may be useful is module attribute deprecation and lazy loading.
::: seealso
`562`{.interpreted-text role="pep"} \-- Module `__getattr__` and `__dir__`
: PEP written and implemented by Ivan Levkivskyi
:::
### PEP 564: New Time Functions With Nanosecond Resolution {#whatsnew37-pep564}
The resolution of clocks in modern systems can exceed the limited precision of a floating-point number returned by the `time.time`{.interpreted-text role="func"} function and its variants. To avoid loss of precision, `564`{.interpreted-text role="pep"} adds six new \"nanosecond\" variants of the existing timer functions to the `time`{.interpreted-text role="mod"} module:
- `time.clock_gettime_ns`{.interpreted-text role="func"}
- `time.clock_settime_ns`{.interpreted-text role="func"}
- `time.monotonic_ns`{.interpreted-text role="func"}
- `time.perf_counter_ns`{.interpreted-text role="func"}
- `time.process_time_ns`{.interpreted-text role="func"}
- `time.time_ns`{.interpreted-text role="func"}
The new functions return the number of nanoseconds as an integer value.
`Measurements <0564#annex-clocks-resolution-in-python>`{.interpreted-text role="pep"} show that on Linux and Windows the resolution of `time.time_ns`{.interpreted-text role="func"} is approximately 3 times better than that of `time.time`{.interpreted-text role="func"}.
::: seealso
`564`{.interpreted-text role="pep"} \-- Add new time functions with nanosecond resolution
: PEP written and implemented by Victor Stinner
:::
### PEP 565: Show DeprecationWarning in `__main__` {#whatsnew37-pep565}
The default handling of `DeprecationWarning`{.interpreted-text role="exc"} has been changed such that these warnings are once more shown by default, but only when the code triggering them is running directly in the `__main__`{.interpreted-text role="mod"} module. As a result, developers of single file scripts and those using Python interactively should once again start seeing deprecation warnings for the APIs they use, but deprecation warnings triggered by imported application, library and framework modules will continue to be hidden by default.
As a result of this change, the standard library now allows developers to choose between three different deprecation warning behaviours:
- `FutureWarning`{.interpreted-text role="exc"}: always displayed by default, recommended for warnings intended to be seen by application end users (e.g. for deprecated application configuration settings).
- `DeprecationWarning`{.interpreted-text role="exc"}: displayed by default only in `__main__`{.interpreted-text role="mod"} and when running tests, recommended for warnings intended to be seen by other Python developers where a version upgrade may result in changed behaviour or an error.
- `PendingDeprecationWarning`{.interpreted-text role="exc"}: displayed by default only when running tests, intended for cases where a future version upgrade will change the warning category to `DeprecationWarning`{.interpreted-text role="exc"} or `FutureWarning`{.interpreted-text role="exc"}.
Previously both `DeprecationWarning`{.interpreted-text role="exc"} and `PendingDeprecationWarning`{.interpreted-text role="exc"} were only visible when running tests, which meant that developers primarily writing single file scripts or using Python interactively could be surprised by breaking changes in the APIs they used.
::: seealso
`565`{.interpreted-text role="pep"} \-- Show DeprecationWarning in `__main__`
: PEP written and implemented by Nick Coghlan
:::
### PEP 560: Core Support for `typing` module and Generic Types {#whatsnew37-pep560}
Initially `484`{.interpreted-text role="pep"} was designed in such way that it would not introduce *any* changes to the core CPython interpreter. Now type hints and the `typing`{.interpreted-text role="mod"} module are extensively used by the community, so this restriction is removed. The PEP introduces two special methods `~object.__class_getitem__`{.interpreted-text role="meth"} and `~object.__mro_entries__`{.interpreted-text role="meth"}, these methods are now used by most classes and special constructs in `typing`{.interpreted-text role="mod"}. As a result, the speed of various operations with types increased up to 7 times, the generic types can be used without metaclass conflicts, and several long standing bugs in `typing`{.interpreted-text role="mod"} module are fixed.
::: seealso
`560`{.interpreted-text role="pep"} \-- Core support for typing module and generic types
: PEP written and implemented by Ivan Levkivskyi
:::
### PEP 552: Hash-based .pyc Files {#whatsnew37-pep552}
Python has traditionally checked the up-to-dateness of bytecode cache files (i.e., `.pyc` files) by comparing the source metadata (last-modified timestamp and size) with source metadata saved in the cache file header when it was generated. While effective, this invalidation method has its drawbacks. When filesystem timestamps are too coarse, Python can miss source updates, leading to user confusion. Additionally, having a timestamp in the cache file is problematic for [build reproducibility](https://reproducible-builds.org/) and content-based build systems.
`552`{.interpreted-text role="pep"} extends the pyc format to allow the hash of the source file to be used for invalidation instead of the source timestamp. Such `.pyc` files are called \"hash-based\". By default, Python still uses timestamp-based invalidation and does not generate hash-based `.pyc` files at runtime. Hash-based `.pyc` files may be generated with `py_compile`{.interpreted-text role="mod"} or `compileall`{.interpreted-text role="mod"}.
Hash-based `.pyc` files come in two variants: checked and unchecked. Python validates checked hash-based `.pyc` files against the corresponding source files at runtime but doesn\'t do so for unchecked hash-based pycs. Unchecked hash-based `.pyc` files are a useful performance optimization for environments where a system external to Python (e.g., the build system) is responsible for keeping `.pyc` files up-to-date.
See `pyc-invalidation`{.interpreted-text role="ref"} for more information.
::: seealso
`552`{.interpreted-text role="pep"} \-- Deterministic pycs
: PEP written and implemented by Benjamin Peterson
:::
### PEP 545: Python Documentation Translations {#whatsnew37-pep545}
`545`{.interpreted-text role="pep"} describes the process of creating and maintaining Python documentation translations.
Three new translations have been added:
- Japanese: <https://docs.python.org/ja/>
- French: <https://docs.python.org/fr/>
- Korean: <https://docs.python.org/ko/>
::: seealso
`545`{.interpreted-text role="pep"} \-- Python Documentation Translations
: PEP written and implemented by Julien Palard, Inada Naoki, and Victor Stinner.
:::
### Python Development Mode (-X dev) {#whatsnew37-devmode}
The new `-X`{.interpreted-text role="option"} `dev` command line option or the new `PYTHONDEVMODE`{.interpreted-text role="envvar"} environment variable can be used to enable `Python Development Mode <devmode>`{.interpreted-text role="ref"}. When in development mode, Python performs additional runtime checks that are too expensive to be enabled by default. See `Python Development Mode <devmode>`{.interpreted-text role="ref"} documentation for the full description.
## Other Language Changes
- An `await`{.interpreted-text role="keyword"} expression and comprehensions containing an `async for`{.interpreted-text role="keyword"} clause were illegal in the expressions in `formatted string literals <f-strings>`{.interpreted-text role="ref"} due to a problem with the implementation. In Python 3.7 this restriction was lifted.
- More than 255 arguments can now be passed to a function, and a function can now have more than 255 parameters. (Contributed by Serhiy Storchaka in `12844`{.interpreted-text role="issue"} and `18896`{.interpreted-text role="issue"}.)
- `bytes.fromhex`{.interpreted-text role="meth"} and `bytearray.fromhex`{.interpreted-text role="meth"} now ignore all ASCII whitespace, not only spaces. (Contributed by Robert Xiao in `28927`{.interpreted-text role="issue"}.)
- `str`{.interpreted-text role="class"}, `bytes`{.interpreted-text role="class"}, and `bytearray`{.interpreted-text role="class"} gained support for the new `isascii() <str.isascii>`{.interpreted-text role="meth"} method, which can be used to test if a string or bytes contain only the ASCII characters. (Contributed by INADA Naoki in `32677`{.interpreted-text role="issue"}.)
- `ImportError`{.interpreted-text role="exc"} now displays module name and module `__file__` path when `from ... import ...` fails. (Contributed by Matthias Bussonnier in `29546`{.interpreted-text role="issue"}.)
- Circular imports involving absolute imports with binding a submodule to a name are now supported. (Contributed by Serhiy Storchaka in `30024`{.interpreted-text role="issue"}.)
- `object.__format__(x, '')` is now equivalent to `str(x)` rather than `format(str(self), '')`. (Contributed by Serhiy Storchaka in `28974`{.interpreted-text role="issue"}.)
- In order to better support dynamic creation of stack traces, `types.TracebackType`{.interpreted-text role="class"} can now be instantiated from Python code, and the `~traceback.tb_next`{.interpreted-text role="attr"} attribute on `tracebacks <traceback-objects>`{.interpreted-text role="ref"} is now writable. (Contributed by Nathaniel J. Smith in `30579`{.interpreted-text role="issue"}.)
- When using the `-m`{.interpreted-text role="option"} switch, `sys.path[0]` is now eagerly expanded to the full starting directory path, rather than being left as the empty directory (which allows imports from the *current* working directory at the time when an import occurs) (Contributed by Nick Coghlan in `33053`{.interpreted-text role="issue"}.)
- The new `-X`{.interpreted-text role="option"} `importtime` option or the `PYTHONPROFILEIMPORTTIME`{.interpreted-text role="envvar"} environment variable can be used to show the timing of each module import. (Contributed by Inada Naoki in `31415`{.interpreted-text role="issue"}.)
## New Modules
### contextvars {#whatsnew37-pep567}
The new `contextvars`{.interpreted-text role="mod"} module and a set of `new C APIs <contextvarsobjects>`{.interpreted-text role="ref"} introduce support for *context variables*. Context variables are conceptually similar to thread-local variables. Unlike TLS, context variables support asynchronous code correctly.
The `asyncio`{.interpreted-text role="mod"} and `decimal`{.interpreted-text role="mod"} modules have been updated to use and support context variables out of the box. Particularly the active decimal context is now stored in a context variable, which allows decimal operations to work with the correct context in asynchronous code.
::: seealso
`567`{.interpreted-text role="pep"} \-- Context Variables
: PEP written and implemented by Yury Selivanov
:::
### dataclasses {#whatsnew37-pep557}
The new `~dataclasses.dataclass`{.interpreted-text role="func"} decorator provides a way to declare *data classes*. A data class describes its attributes using class variable annotations. Its constructor and other magic methods, such as `~object.__repr__`{.interpreted-text role="meth"}, `~object.__eq__`{.interpreted-text role="meth"}, and `~object.__hash__`{.interpreted-text role="meth"} are generated automatically.
Example:
@dataclass
class Point:
x: float
y: float
z: float = 0.0
p = Point(1.5, 2.5)
print(p) # produces "Point(x=1.5, y=2.5, z=0.0)"
::: seealso
`557`{.interpreted-text role="pep"} \-- Data Classes
: PEP written and implemented by Eric V. Smith
:::
### importlib.resources {#whatsnew37_importlib_resources}
The new `importlib.resources`{.interpreted-text role="mod"} module provides several new APIs and one new ABC for access to, opening, and reading *resources* inside packages. Resources are roughly similar to files inside packages, but they needn\'t be actual files on the physical file system. Module loaders can provide a `!get_resource_reader`{.interpreted-text role="meth"} function which returns a `!importlib.abc.ResourceReader`{.interpreted-text role="class"} instance to support this new API. Built-in file path loaders and zip file loaders both support this.
Contributed by Barry Warsaw and Brett Cannon in `32248`{.interpreted-text role="issue"}.
::: seealso
[importlib_resources](https://importlib-resources.readthedocs.io/en/latest/) \-- a PyPI backport for earlier Python versions.
:::
## Improved Modules
### argparse
The new `ArgumentParser.parse_intermixed_args()
<argparse.ArgumentParser.parse_intermixed_args>`{.interpreted-text role="meth"} method allows intermixing options and positional arguments. (Contributed by paul.j3 in `14191`{.interpreted-text role="issue"}.)
### asyncio {#whatsnew37_asyncio}
The `asyncio`{.interpreted-text role="mod"} module has received many new features, usability and `performance improvements <whatsnew37-asyncio-perf>`{.interpreted-text role="ref"}. Notable changes include:
- The new `provisional <provisional API>`{.interpreted-text role="term"} `asyncio.run`{.interpreted-text role="func"} function can be used to run a coroutine from synchronous code by automatically creating and destroying the event loop. (Contributed by Yury Selivanov in `32314`{.interpreted-text role="issue"}.)
- asyncio gained support for `contextvars`{.interpreted-text role="mod"}. `loop.call_soon() <asyncio.loop.call_soon>`{.interpreted-text role="meth"}, `loop.call_soon_threadsafe() <asyncio.loop.call_soon_threadsafe>`{.interpreted-text role="meth"}, `loop.call_later() <asyncio.loop.call_later>`{.interpreted-text role="meth"}, `loop.call_at() <asyncio.loop.call_at>`{.interpreted-text role="meth"}, and `Future.add_done_callback() <asyncio.Future.add_done_callback>`{.interpreted-text role="meth"} have a new optional keyword-only *context* parameter. `Tasks <asyncio.Task>`{.interpreted-text role="class"} now track their context automatically. See `567`{.interpreted-text role="pep"} for more details. (Contributed by Yury Selivanov in `32436`{.interpreted-text role="issue"}.)
- The new `asyncio.create_task`{.interpreted-text role="func"} function has been added as a shortcut to `asyncio.get_event_loop().create_task()`. (Contributed by Andrew Svetlov in `32311`{.interpreted-text role="issue"}.)
- The new `loop.start_tls() <asyncio.loop.start_tls>`{.interpreted-text role="meth"} method can be used to upgrade an existing connection to TLS. (Contributed by Yury Selivanov in `23749`{.interpreted-text role="issue"}.)
- The new `loop.sock_recv_into() <asyncio.loop.sock_recv_into>`{.interpreted-text role="meth"} method allows reading data from a socket directly into a provided buffer making it possible to reduce data copies. (Contributed by Antoine Pitrou in `31819`{.interpreted-text role="issue"}.)
- The new `asyncio.current_task`{.interpreted-text role="func"} function returns the currently running `~asyncio.Task`{.interpreted-text role="class"} instance, and the new `asyncio.all_tasks`{.interpreted-text role="func"} function returns a set of all existing `Task` instances in a given loop. The `!Task.current_task`{.interpreted-text role="meth"} and `!Task.all_tasks`{.interpreted-text role="meth"} methods have been deprecated. (Contributed by Andrew Svetlov in `32250`{.interpreted-text role="issue"}.)
- The new *provisional* `~asyncio.BufferedProtocol`{.interpreted-text role="class"} class allows implementing streaming protocols with manual control over the receive buffer. (Contributed by Yury Selivanov in `32251`{.interpreted-text role="issue"}.)
- The new `asyncio.get_running_loop`{.interpreted-text role="func"} function returns the currently running loop, and raises a `RuntimeError`{.interpreted-text role="exc"} if no loop is running. This is in contrast with `asyncio.get_event_loop`{.interpreted-text role="func"}, which will *create* a new event loop if none is running. (Contributed by Yury Selivanov in `32269`{.interpreted-text role="issue"}.)
- The new `StreamWriter.wait_closed() <asyncio.StreamWriter.wait_closed>`{.interpreted-text role="meth"} coroutine method allows waiting until the stream writer is closed. The new `StreamWriter.is_closing() <asyncio.StreamWriter.is_closing>`{.interpreted-text role="meth"} method can be used to determine if the writer is closing. (Contributed by Andrew Svetlov in `32391`{.interpreted-text role="issue"}.)
- The new `loop.sock_sendfile() <asyncio.loop.sock_sendfile>`{.interpreted-text role="meth"} coroutine method allows sending files using `os.sendfile`{.interpreted-text role="mod"} when possible. (Contributed by Andrew Svetlov in `32410`{.interpreted-text role="issue"}.)
- The new `Future.get_loop() <asyncio.Future.get_loop>`{.interpreted-text role="meth"} and `Task.get_loop()` methods return the instance of the loop on which a task or a future were created. `Server.get_loop() <asyncio.Server.get_loop>`{.interpreted-text role="meth"} allows doing the same for `asyncio.Server`{.interpreted-text role="class"} objects. (Contributed by Yury Selivanov in `32415`{.interpreted-text role="issue"} and Srinivas Reddy Thatiparthy in `32418`{.interpreted-text role="issue"}.)
- It is now possible to control how instances of `asyncio.Server`{.interpreted-text role="class"} begin serving. Previously, the server would start serving immediately when created. The new *start_serving* keyword argument to `loop.create_server() <asyncio.loop.create_server>`{.interpreted-text role="meth"} and `loop.create_unix_server() <asyncio.loop.create_unix_server>`{.interpreted-text role="meth"}, as well as `Server.start_serving() <asyncio.Server.start_serving>`{.interpreted-text role="meth"}, and `Server.serve_forever() <asyncio.Server.serve_forever>`{.interpreted-text role="meth"} can be used to decouple server instantiation and serving. The new `Server.is_serving() <asyncio.Server.is_serving>`{.interpreted-text role="meth"} method returns `True` if the server is serving. `~asyncio.Server`{.interpreted-text role="class"} objects are now asynchronous context managers:
srv = await loop.create_server(...)
async with srv:
# some code
# At this point, srv is closed and no longer accepts new connections.
(Contributed by Yury Selivanov in `32662`{.interpreted-text role="issue"}.)
- Callback objects returned by `loop.call_later() <asyncio.loop.call_later>`{.interpreted-text role="func"} gained the new `when() <asyncio.TimerHandle.when>`{.interpreted-text role="meth"} method which returns an absolute scheduled callback timestamp. (Contributed by Andrew Svetlov in `32741`{.interpreted-text role="issue"}.)
- The :meth:\`loop.create_datagram_endpoint() \<asyncio.loop.create_datagram_endpoint\>\` method gained support for Unix sockets. (Contributed by Quentin Dawans in `31245`{.interpreted-text role="issue"}.)
- The `asyncio.open_connection`{.interpreted-text role="func"}, `asyncio.start_server`{.interpreted-text role="func"} functions, `loop.create_connection() <asyncio.loop.create_connection>`{.interpreted-text role="meth"}, `loop.create_server() <asyncio.loop.create_server>`{.interpreted-text role="meth"}, `loop.create_accepted_socket() <asyncio.loop.connect_accepted_socket>`{.interpreted-text role="meth"} methods and their corresponding UNIX socket variants now accept the *ssl_handshake_timeout* keyword argument. (Contributed by Neil Aspinall in `29970`{.interpreted-text role="issue"}.)
- The new `Handle.cancelled() <asyncio.Handle.cancelled>`{.interpreted-text role="meth"} method returns `True` if the callback was cancelled. (Contributed by Marat Sharafutdinov in `31943`{.interpreted-text role="issue"}.)
- The asyncio source has been converted to use the `async`{.interpreted-text role="keyword"}/`await`{.interpreted-text role="keyword"} syntax. (Contributed by Andrew Svetlov in `32193`{.interpreted-text role="issue"}.)
- The new `ReadTransport.is_reading() <asyncio.ReadTransport.is_reading>`{.interpreted-text role="meth"} method can be used to determine the reading state of the transport. Additionally, calls to `ReadTransport.resume_reading() <asyncio.ReadTransport.resume_reading>`{.interpreted-text role="meth"} and `ReadTransport.pause_reading() <asyncio.ReadTransport.pause_reading>`{.interpreted-text role="meth"} are now idempotent. (Contributed by Yury Selivanov in `32356`{.interpreted-text role="issue"}.)
- Loop methods which accept socket paths now support passing `path-like objects <path-like object>`{.interpreted-text role="term"}. (Contributed by Yury Selivanov in `32066`{.interpreted-text role="issue"}.)
- In `asyncio`{.interpreted-text role="mod"} TCP sockets on Linux are now created with `TCP_NODELAY` flag set by default. (Contributed by Yury Selivanov and Victor Stinner in `27456`{.interpreted-text role="issue"}.)
- Exceptions occurring in cancelled tasks are no longer logged. (Contributed by Yury Selivanov in `30508`{.interpreted-text role="issue"}.)
- New `WindowsSelectorEventLoopPolicy` and `WindowsProactorEventLoopPolicy` classes. (Contributed by Yury Selivanov in `33792`{.interpreted-text role="issue"}.)
Several `asyncio` APIs have been `deprecated <whatsnew37-asyncio-deprecated>`{.interpreted-text role="ref"}.
### binascii
The `~binascii.b2a_uu`{.interpreted-text role="func"} function now accepts an optional *backtick* keyword argument. When it\'s true, zeros are represented by `` '`' `` instead of spaces. (Contributed by Xiang Zhang in `30103`{.interpreted-text role="issue"}.)
### calendar
The `~calendar.HTMLCalendar`{.interpreted-text role="class"} class has new class attributes which ease the customization of CSS classes in the produced HTML calendar. (Contributed by Oz Tiram in `30095`{.interpreted-text role="issue"}.)
### collections
`collections.namedtuple()` now supports default values. (Contributed by Raymond Hettinger in `32320`{.interpreted-text role="issue"}.)
### compileall
`compileall.compile_dir`{.interpreted-text role="func"} learned the new *invalidation_mode* parameter, which can be used to enable `hash-based .pyc invalidation <whatsnew37-pep552>`{.interpreted-text role="ref"}. The invalidation mode can also be specified on the command line using the new `--invalidation-mode` argument. (Contributed by Benjamin Peterson in `31650`{.interpreted-text role="issue"}.)
### concurrent.futures
`ProcessPoolExecutor <concurrent.futures.ProcessPoolExecutor>`{.interpreted-text role="class"} and `ThreadPoolExecutor <concurrent.futures.ThreadPoolExecutor>`{.interpreted-text role="class"} now support the new *initializer* and *initargs* constructor arguments. (Contributed by Antoine Pitrou in `21423`{.interpreted-text role="issue"}.)
The `ProcessPoolExecutor <concurrent.futures.ProcessPoolExecutor>`{.interpreted-text role="class"} can now take the multiprocessing context via the new *mp_context* argument. (Contributed by Thomas Moreau in `31540`{.interpreted-text role="issue"}.)
### contextlib
The new `~contextlib.nullcontext`{.interpreted-text role="func"} is a simpler and faster no-op context manager than `~contextlib.ExitStack`{.interpreted-text role="class"}. (Contributed by Jesse-Bakker in `10049`{.interpreted-text role="issue"}.)
The new `~contextlib.asynccontextmanager`{.interpreted-text role="func"}, `~contextlib.AbstractAsyncContextManager`{.interpreted-text role="class"}, and `~contextlib.AsyncExitStack`{.interpreted-text role="class"} have been added to complement their synchronous counterparts. (Contributed by Jelle Zijlstra in `29679`{.interpreted-text role="issue"} and `30241`{.interpreted-text role="issue"}, and by Alexander Mohr and Ilya Kulakov in `29302`{.interpreted-text role="issue"}.)
### cProfile
The `!cProfile`{.interpreted-text role="mod"} command line now accepts `-m module_name` as an alternative to script path. (Contributed by Sanyam Khurana in `21862`{.interpreted-text role="issue"}.)
### crypt
The `!crypt`{.interpreted-text role="mod"} module now supports the Blowfish hashing method. (Contributed by Serhiy Storchaka in `31664`{.interpreted-text role="issue"}.)
The `!mksalt`{.interpreted-text role="func"} function now allows specifying the number of rounds for hashing. (Contributed by Serhiy Storchaka in `31702`{.interpreted-text role="issue"}.)
### datetime
The new `datetime.fromisoformat() <datetime.datetime.fromisoformat>`{.interpreted-text role="meth"} method constructs a `~datetime.datetime`{.interpreted-text role="class"} object from a string in one of the formats output by `datetime.isoformat() <datetime.datetime.isoformat>`{.interpreted-text role="meth"}. (Contributed by Paul Ganssle in `15873`{.interpreted-text role="issue"}.)
The `tzinfo <datetime.tzinfo>`{.interpreted-text role="class"} class now supports sub-minute offsets. (Contributed by Alexander Belopolsky in `5288`{.interpreted-text role="issue"}.)
### dbm
`dbm.dumb`{.interpreted-text role="mod"} now supports reading read-only files and no longer writes the index file when it is not changed.
### decimal
The `decimal`{.interpreted-text role="mod"} module now uses `context variables <whatsnew37-pep567>`{.interpreted-text role="ref"} to store the decimal context. (Contributed by Yury Selivanov in `32630`{.interpreted-text role="issue"}.)
### dis
The `~dis.dis`{.interpreted-text role="func"} function is now able to disassemble nested code objects (the code of comprehensions, generator expressions and nested functions, and the code used for building nested classes). The maximum depth of disassembly recursion is controlled by the new *depth* parameter. (Contributed by Serhiy Storchaka in `11822`{.interpreted-text role="issue"}.)
### distutils
`README.rst` is now included in the list of distutils standard READMEs and therefore included in source distributions. (Contributed by Ryan Gonzalez in `11913`{.interpreted-text role="issue"}.)
### enum
The `Enum <enum.Enum>`{.interpreted-text role="class"} learned the new `_ignore_` class property, which allows listing the names of properties which should not become enum members. (Contributed by Ethan Furman in `31801`{.interpreted-text role="issue"}.)
In Python 3.8, attempting to check for non-Enum objects in `~enum.Enum`{.interpreted-text role="class"} classes will raise a `TypeError`{.interpreted-text role="exc"} (e.g. `1 in Color`); similarly, attempting to check for non-Flag objects in a `~enum.Flag`{.interpreted-text role="class"} member will raise `TypeError`{.interpreted-text role="exc"} (e.g. `1 in Perm.RW`); currently, both operations return `False`{.interpreted-text role="const"} instead and are deprecated. (Contributed by Ethan Furman in `33217`{.interpreted-text role="issue"}.)
### functools
`functools.singledispatch`{.interpreted-text role="func"} now supports registering implementations using type annotations. (Contributed by Łukasz Langa in `32227`{.interpreted-text role="issue"}.)
### gc
The new `gc.freeze`{.interpreted-text role="func"} function allows freezing all objects tracked by the garbage collector and excluding them from future collections. This can be used before a POSIX `fork()` call to make the GC copy-on-write friendly or to speed up collection. The new `gc.unfreeze`{.interpreted-text role="func"} functions reverses this operation. Additionally, `gc.get_freeze_count`{.interpreted-text role="func"} can be used to obtain the number of frozen objects. (Contributed by Li Zekun in `31558`{.interpreted-text role="issue"}.)
### hmac
The `hmac`{.interpreted-text role="mod"} module now has an optimized one-shot `~hmac.digest`{.interpreted-text role="func"} function, which is up to three times faster than `~hmac.HMAC`{.interpreted-text role="func"}. (Contributed by Christian Heimes in `32433`{.interpreted-text role="issue"}.)
### http.client
`~http.client.HTTPConnection`{.interpreted-text role="class"} and `~http.client.HTTPSConnection`{.interpreted-text role="class"} now support the new *blocksize* argument for improved upload throughput. (Contributed by Nir Soffer in `31945`{.interpreted-text role="issue"}.)
### http.server
`~http.server.SimpleHTTPRequestHandler`{.interpreted-text role="class"} now supports the HTTP `If-Modified-Since` header. The server returns the 304 response status if the target file was not modified after the time specified in the header. (Contributed by Pierre Quentel in `29654`{.interpreted-text role="issue"}.)
`~http.server.SimpleHTTPRequestHandler`{.interpreted-text role="class"} accepts the new *directory* argument, in addition to the new `--directory` command line argument. With this parameter, the server serves the specified directory, by default it uses the current working directory. (Contributed by Stéphane Wirtel and Julien Palard in `28707`{.interpreted-text role="issue"}.)
The new `ThreadingHTTPServer <http.server.ThreadingHTTPServer>`{.interpreted-text role="class"} class uses threads to handle requests using `~socketserver.ThreadingMixIn`{.interpreted-text role="class"}. It is used when `http.server` is run with `-m`. (Contributed by Julien Palard in `31639`{.interpreted-text role="issue"}.)
### idlelib and IDLE
Multiple fixes for autocompletion. (Contributed by Louie Lu in `15786`{.interpreted-text role="issue"}.)
Module Browser (on the File menu, formerly called Class Browser), now displays nested functions and classes in addition to top-level functions and classes. (Contributed by Guilherme Polo, Cheryl Sabella, and Terry Jan Reedy in `1612262`{.interpreted-text role="issue"}.)
The Settings dialog (Options, Configure IDLE) has been partly rewritten to improve both appearance and function. (Contributed by Cheryl Sabella and Terry Jan Reedy in multiple issues.)
The font sample now includes a selection of non-Latin characters so that users can better see the effect of selecting a particular font. (Contributed by Terry Jan Reedy in `13802`{.interpreted-text role="issue"}.) The sample can be edited to include other characters. (Contributed by Serhiy Storchaka in `31860`{.interpreted-text role="issue"}.)
The IDLE features formerly implemented as extensions have been reimplemented as normal features. Their settings have been moved from the Extensions tab to other dialog tabs. (Contributed by Charles Wohlganger and Terry Jan Reedy in `27099`{.interpreted-text role="issue"}.)
Editor code context option revised. Box displays all context lines up to maxlines. Clicking on a context line jumps the editor to that line. Context colors for custom themes is added to Highlights tab of Settings dialog. (Contributed by Cheryl Sabella and Terry Jan Reedy in `33642`{.interpreted-text role="issue"}, `33768`{.interpreted-text role="issue"}, and `33679`{.interpreted-text role="issue"}.)
On Windows, a new API call tells Windows that tk scales for DPI. On Windows 8.1+ or 10, with DPI compatibility properties of the Python binary unchanged, and a monitor resolution greater than 96 DPI, this should make text and lines sharper. It should otherwise have no effect. (Contributed by Terry Jan Reedy in `33656`{.interpreted-text role="issue"}.)
New in 3.7.1:
Output over N lines (50 by default) is squeezed down to a button. N can be changed in the PyShell section of the General page of the Settings dialog. Fewer, but possibly extra long, lines can be squeezed by right clicking on the output. Squeezed output can be expanded in place by double-clicking the button or into the clipboard or a separate window by right-clicking the button. (Contributed by Tal Einat in `1529353`{.interpreted-text role="issue"}.)
The changes above have been backported to 3.6 maintenance releases.
NEW in 3.7.4:
Add \"Run Customized\" to the Run menu to run a module with customized settings. Any command line arguments entered are added to sys.argv. They re-appear in the box for the next customized run. One can also suppress the normal Shell main module restart. (Contributed by Cheryl Sabella, Terry Jan Reedy, and others in `5680`{.interpreted-text role="issue"} and `37627`{.interpreted-text role="issue"}.)
New in 3.7.5:
Add optional line numbers for IDLE editor windows. Windows open without line numbers unless set otherwise in the General tab of the configuration dialog. Line numbers for an existing window are shown and hidden in the Options menu. (Contributed by Tal Einat and Saimadhav Heblikar in `17535`{.interpreted-text role="issue"}.)
### importlib
The `!importlib.abc.ResourceReader`{.interpreted-text role="class"} ABC was introduced to support the loading of resources from packages. See also `whatsnew37_importlib_resources`{.interpreted-text role="ref"}. (Contributed by Barry Warsaw, Brett Cannon in `32248`{.interpreted-text role="issue"}.)
`importlib.reload`{.interpreted-text role="func"} now raises `ModuleNotFoundError`{.interpreted-text role="exc"} if the module lacks a spec. (Contributed by Garvit Khatri in `29851`{.interpreted-text role="issue"}.)
`importlib.util.find_spec`{.interpreted-text role="func"} now raises `ModuleNotFoundError`{.interpreted-text role="exc"} instead of `AttributeError`{.interpreted-text role="exc"} if the specified parent module is not a package (i.e. lacks a `__path__` attribute). (Contributed by Milan Oberkirch in `30436`{.interpreted-text role="issue"}.)
The new `importlib.util.source_hash`{.interpreted-text role="func"} can be used to compute the hash of the passed source. A `hash-based .pyc file <whatsnew37-pep552>`{.interpreted-text role="ref"} embeds the value returned by this function.
### io
The new `TextIOWrapper.reconfigure() <io.TextIOWrapper.reconfigure>`{.interpreted-text role="meth"} method can be used to reconfigure the text stream with the new settings. (Contributed by Antoine Pitrou in `30526`{.interpreted-text role="issue"} and INADA Naoki in `15216`{.interpreted-text role="issue"}.)
### ipaddress
The new `subnet_of()` and `supernet_of()` methods of `ipaddress.IPv6Network`{.interpreted-text role="class"} and `ipaddress.IPv4Network`{.interpreted-text role="class"} can be used for network containment tests. (Contributed by Michel Albert and Cheryl Sabella in `20825`{.interpreted-text role="issue"}.)
### itertools
`itertools.islice`{.interpreted-text role="func"} now accepts `integer-like objects <object.__index__>`{.interpreted-text role="meth"} as start, stop, and slice arguments. (Contributed by Will Roberts in `30537`{.interpreted-text role="issue"}.)
### locale
The new *monetary* argument to `locale.format_string`{.interpreted-text role="func"} can be used to make the conversion use monetary thousands separators and grouping strings. (Contributed by Garvit in `10379`{.interpreted-text role="issue"}.)
The `locale.getpreferredencoding`{.interpreted-text role="func"} function now always returns `'UTF-8'` on Android or when in the `forced UTF-8 mode <whatsnew37-pep540>`{.interpreted-text role="ref"}.
### logging
`~logging.Logger`{.interpreted-text role="class"} instances can now be pickled. (Contributed by Vinay Sajip in `30520`{.interpreted-text role="issue"}.)
The new `StreamHandler.setStream() <logging.StreamHandler.setStream>`{.interpreted-text role="meth"} method can be used to replace the logger stream after handler creation. (Contributed by Vinay Sajip in `30522`{.interpreted-text role="issue"}.)
It is now possible to specify keyword arguments to handler constructors in configuration passed to `logging.config.fileConfig`{.interpreted-text role="func"}. (Contributed by Preston Landers in `31080`{.interpreted-text role="issue"}.)
### math
The new `math.remainder`{.interpreted-text role="func"} function implements the IEEE 754-style remainder operation. (Contributed by Mark Dickinson in `29962`{.interpreted-text role="issue"}.)
### mimetypes
The MIME type of .bmp has been changed from `'image/x-ms-bmp'` to `'image/bmp'`. (Contributed by Nitish Chandra in `22589`{.interpreted-text role="issue"}.)
### msilib
The new `!Database.Close`{.interpreted-text role="meth"} method can be used to close the `MSI`{.interpreted-text role="abbr"} database. (Contributed by Berker Peksag in `20486`{.interpreted-text role="issue"}.)
### multiprocessing
The new `Process.close() <multiprocessing.Process.close>`{.interpreted-text role="meth"} method explicitly closes the process object and releases all resources associated with it. `ValueError`{.interpreted-text role="exc"} is raised if the underlying process is still running. (Contributed by Antoine Pitrou in `30596`{.interpreted-text role="issue"}.)
The new `Process.kill() <multiprocessing.Process.kill>`{.interpreted-text role="meth"} method can be used to terminate the process using the `~signal.SIGKILL`{.interpreted-text role="data"} signal on Unix. (Contributed by Vitor Pereira in `30794`{.interpreted-text role="issue"}.)
Non-daemonic threads created by `~multiprocessing.Process`{.interpreted-text role="class"} are now joined on process exit. (Contributed by Antoine Pitrou in `18966`{.interpreted-text role="issue"}.)
### os
`os.fwalk`{.interpreted-text role="func"} now accepts the *path* argument as `bytes`{.interpreted-text role="class"}. (Contributed by Serhiy Storchaka in `28682`{.interpreted-text role="issue"}.)
`os.scandir`{.interpreted-text role="func"} gained support for `file descriptors <path_fd>`{.interpreted-text role="ref"}. (Contributed by Serhiy Storchaka in `25996`{.interpreted-text role="issue"}.)
The new `~os.register_at_fork`{.interpreted-text role="func"} function allows registering Python callbacks to be executed at process fork. (Contributed by Antoine Pitrou in `16500`{.interpreted-text role="issue"}.)
Added `os.preadv`{.interpreted-text role="func"} (combine the functionality of `os.readv`{.interpreted-text role="func"} and `os.pread`{.interpreted-text role="func"}) and `os.pwritev`{.interpreted-text role="func"} functions (combine the functionality of `os.writev`{.interpreted-text role="func"} and `os.pwrite`{.interpreted-text role="func"}). (Contributed by Pablo Galindo in `31368`{.interpreted-text role="issue"}.)
The mode argument of `os.makedirs`{.interpreted-text role="func"} no longer affects the file permission bits of newly created intermediate-level directories. (Contributed by Serhiy Storchaka in `19930`{.interpreted-text role="issue"}.)
`os.dup2`{.interpreted-text role="func"} now returns the new file descriptor. Previously, `None` was always returned. (Contributed by Benjamin Peterson in `32441`{.interpreted-text role="issue"}.)
The structure returned by `os.stat`{.interpreted-text role="func"} now contains the `~os.stat_result.st_fstype`{.interpreted-text role="attr"} attribute on Solaris and its derivatives. (Contributed by Jesús Cea Avión in `32659`{.interpreted-text role="issue"}.)
### pathlib
The new `Path.is_mount() <pathlib.Path.is_mount>`{.interpreted-text role="meth"} method is now available on POSIX systems and can be used to determine whether a path is a mount point. (Contributed by Cooper Ry Lees in `30897`{.interpreted-text role="issue"}.)
### pdb
`pdb.set_trace`{.interpreted-text role="func"} now takes an optional *header* keyword-only argument. If given, it is printed to the console just before debugging begins. (Contributed by Barry Warsaw in `31389`{.interpreted-text role="issue"}.)
`pdb`{.interpreted-text role="mod"} command line now accepts `-m module_name` as an alternative to script file. (Contributed by Mario Corchero in `32206`{.interpreted-text role="issue"}.)
### py_compile
`py_compile.compile`{.interpreted-text role="func"} \-- and by extension, `compileall`{.interpreted-text role="mod"} \-- now respects the `SOURCE_DATE_EPOCH`{.interpreted-text role="envvar"} environment variable by unconditionally creating `.pyc` files for hash-based validation. This allows for guaranteeing [reproducible builds](https://reproducible-builds.org/) of `.pyc` files when they are created eagerly. (Contributed by Bernhard M. Wiedemann in `29708`{.interpreted-text role="issue"}.)
### pydoc
The pydoc server can now bind to an arbitrary hostname specified by the new `-n` command-line argument. (Contributed by Feanil Patel in `31128`{.interpreted-text role="issue"}.)
### queue
The new `~queue.SimpleQueue`{.interpreted-text role="class"} class is an unbounded `FIFO`{.interpreted-text role="abbr"} queue. (Contributed by Antoine Pitrou in `14976`{.interpreted-text role="issue"}.)
### re
The flags `re.ASCII`{.interpreted-text role="const"}, `re.LOCALE`{.interpreted-text role="const"} and `re.UNICODE`{.interpreted-text role="const"} can be set within the scope of a group. (Contributed by Serhiy Storchaka in `31690`{.interpreted-text role="issue"}.)
`re.split`{.interpreted-text role="func"} now supports splitting on a pattern like `r'\b'`, `'^$'` or `(?=-)` that matches an empty string. (Contributed by Serhiy Storchaka in `25054`{.interpreted-text role="issue"}.)
Regular expressions compiled with the `re.LOCALE`{.interpreted-text role="const"} flag no longer depend on the locale at compile time. Locale settings are applied only when the compiled regular expression is used. (Contributed by Serhiy Storchaka in `30215`{.interpreted-text role="issue"}.)
`FutureWarning`{.interpreted-text role="exc"} is now emitted if a regular expression contains character set constructs that will change semantically in the future, such as nested sets and set operations. (Contributed by Serhiy Storchaka in `30349`{.interpreted-text role="issue"}.)
Compiled regular expression and match objects can now be copied using `copy.copy`{.interpreted-text role="func"} and `copy.deepcopy`{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in `10076`{.interpreted-text role="issue"}.)
### signal
The new *warn_on_full_buffer* argument to the `signal.set_wakeup_fd`{.interpreted-text role="func"} function makes it possible to specify whether Python prints a warning on stderr when the wakeup buffer overflows. (Contributed by Nathaniel J. Smith in `30050`{.interpreted-text role="issue"}.)
### socket
The new `socket.getblocking() <socket.socket.getblocking>`{.interpreted-text role="func"} method returns `True` if the socket is in blocking mode and `False` otherwise. (Contributed by Yury Selivanov in `32373`{.interpreted-text role="issue"}.)
The new `socket.close`{.interpreted-text role="func"} function closes the passed socket file descriptor. This function should be used instead of `os.close`{.interpreted-text role="func"} for better compatibility across platforms. (Contributed by Christian Heimes in `32454`{.interpreted-text role="issue"}.)
The `socket`{.interpreted-text role="mod"} module now exposes the `socket.TCP_CONGESTION
<socket-unix-constants>`{.interpreted-text role="ref"} (Linux 2.6.13), `socket.TCP_USER_TIMEOUT
<socket-unix-constants>`{.interpreted-text role="ref"} (Linux 2.6.37), and `socket.TCP_NOTSENT_LOWAT
<socket-unix-constants>`{.interpreted-text role="ref"} (Linux 3.12) constants. (Contributed by Omar Sandoval in `26273`{.interpreted-text role="issue"} and Nathaniel J. Smith in `29728`{.interpreted-text role="issue"}.)
Support for `socket.AF_VSOCK`{.interpreted-text role="const"} sockets has been added to allow communication between virtual machines and their hosts. (Contributed by Cathy Avery in `27584`{.interpreted-text role="issue"}.)
Sockets now auto-detect family, type and protocol from file descriptor by default. (Contributed by Christian Heimes in `28134`{.interpreted-text role="issue"}.)
### socketserver
`socketserver.ThreadingMixIn.server_close
<socketserver.BaseServer.server_close>`{.interpreted-text role="meth"} now waits until all non-daemon threads complete. `socketserver.ForkingMixIn.server_close
<socketserver.BaseServer.server_close>`{.interpreted-text role="meth"} now waits until all child processes complete.
Add a new `socketserver.ForkingMixIn.block_on_close
<socketserver.ThreadingMixIn.block_on_close>`{.interpreted-text role="attr"} class attribute to `socketserver.ForkingMixIn`{.interpreted-text role="class"} and `socketserver.ThreadingMixIn`{.interpreted-text role="class"} classes. Set the class attribute to `False` to get the pre-3.7 behaviour.
### sqlite3
`sqlite3.Connection`{.interpreted-text role="class"} now exposes the `~sqlite3.Connection.backup`{.interpreted-text role="meth"} method when the underlying SQLite library is at version 3.6.11 or higher. (Contributed by Lele Gaifax in `27645`{.interpreted-text role="issue"}.)
The *database* argument of `sqlite3.connect`{.interpreted-text role="func"} now accepts any `path-like object`{.interpreted-text role="term"}, instead of just a string. (Contributed by Anders Lorentsen in `31843`{.interpreted-text role="issue"}.)
### ssl
The `ssl`{.interpreted-text role="mod"} module now uses OpenSSL\'s builtin API instead of `!match_hostname`{.interpreted-text role="func"} to check a host name or an IP address. Values are validated during TLS handshake. Any certificate validation error including failing the host name check now raises `~ssl.SSLCertVerificationError`{.interpreted-text role="exc"} and aborts the handshake with a proper TLS Alert message. The new exception contains additional information. Host name validation can be customized with `SSLContext.hostname_checks_common_name <ssl.SSLContext.hostname_checks_common_name>`{.interpreted-text role="attr"}. (Contributed by Christian Heimes in `31399`{.interpreted-text role="issue"}.)
:::: note
::: title
Note
:::
The improved host name check requires a *libssl* implementation compatible with OpenSSL 1.0.2 or 1.1. Consequently, OpenSSL 0.9.8 and 1.0.1 are no longer supported (see `37-platform-support-removals`{.interpreted-text role="ref"} for more details). The ssl module is mostly compatible with LibreSSL 2.7.2 and newer.
::::
The `ssl` module no longer sends IP addresses in SNI TLS extension. (Contributed by Christian Heimes in `32185`{.interpreted-text role="issue"}.)
`!match_hostname`{.interpreted-text role="func"} no longer supports partial wildcards like `www*.example.org`. (Contributed by Mandeep Singh in `23033`{.interpreted-text role="issue"} and Christian Heimes in `31399`{.interpreted-text role="issue"}.)
The default cipher suite selection of the `ssl` module now uses a blacklist approach rather than a hard-coded whitelist. Python no longer re-enables ciphers that have been blocked by OpenSSL security updates. Default cipher suite selection can be configured at compile time. (Contributed by Christian Heimes in `31429`{.interpreted-text role="issue"}.)
Validation of server certificates containing internationalized domain names (IDNs) is now supported. As part of this change, the `SSLSocket.server_hostname <ssl.SSLSocket.server_hostname>`{.interpreted-text role="attr"} attribute now stores the expected hostname in A-label form (`"xn--pythn-mua.org"`), rather than the U-label form (`"pythön.org"`). (Contributed by Nathaniel J. Smith and Christian Heimes in `28414`{.interpreted-text role="issue"}.)
The `ssl` module has preliminary and experimental support for TLS 1.3 and OpenSSL 1.1.1. At the time of Python 3.7.0 release, OpenSSL 1.1.1 is still under development and TLS 1.3 hasn\'t been finalized yet. The TLS 1.3 handshake and protocol behaves slightly differently than TLS 1.2 and earlier, see `ssl-tlsv1_3`{.interpreted-text role="ref"}. (Contributed by Christian Heimes in `32947`{.interpreted-text role="issue"}, `20995`{.interpreted-text role="issue"}, `29136`{.interpreted-text role="issue"}, `30622`{.interpreted-text role="issue"} and `33618`{.interpreted-text role="issue"})
`~ssl.SSLSocket`{.interpreted-text role="class"} and `~ssl.SSLObject`{.interpreted-text role="class"} no longer have a public constructor. Direct instantiation was never a documented and supported feature. Instances must be created with `~ssl.SSLContext`{.interpreted-text role="class"} methods `~ssl.SSLContext.wrap_socket`{.interpreted-text role="meth"} and `~ssl.SSLContext.wrap_bio`{.interpreted-text role="meth"}. (Contributed by Christian Heimes in `32951`{.interpreted-text role="issue"})
OpenSSL 1.1 APIs for setting the minimum and maximum TLS protocol version are available as `SSLContext.minimum_version <ssl.SSLContext.minimum_version>`{.interpreted-text role="attr"} and `SSLContext.maximum_version <ssl.SSLContext.maximum_version>`{.interpreted-text role="attr"}. Supported protocols are indicated by several new flags, such as `~ssl.HAS_TLSv1_1`{.interpreted-text role="data"}. (Contributed by Christian Heimes in `32609`{.interpreted-text role="issue"}.)
Added `ssl.SSLContext.post_handshake_auth`{.interpreted-text role="attr"} to enable and `ssl.SSLSocket.verify_client_post_handshake`{.interpreted-text role="meth"} to initiate TLS 1.3 post-handshake authentication. (Contributed by Christian Heimes in `78851`{.interpreted-text role="gh"}.)
### string
`string.Template`{.interpreted-text role="class"} now lets you to optionally modify the regular expression pattern for braced placeholders and non-braced placeholders separately. (Contributed by Barry Warsaw in `1198569`{.interpreted-text role="issue"}.)
### subprocess
The `subprocess.run`{.interpreted-text role="func"} function accepts the new *capture_output* keyword argument. When true, stdout and stderr will be captured. This is equivalent to passing `subprocess.PIPE`{.interpreted-text role="const"} as *stdout* and *stderr* arguments. (Contributed by Bo Bayles in `32102`{.interpreted-text role="issue"}.)
The `subprocess.run` function and the `subprocess.Popen`{.interpreted-text role="class"} constructor now accept the *text* keyword argument as an alias to *universal_newlines*. (Contributed by Andrew Clegg in `31756`{.interpreted-text role="issue"}.)
On Windows the default for *close_fds* was changed from `False` to `True` when redirecting the standard handles. It\'s now possible to set *close_fds* to true when redirecting the standard handles. See `subprocess.Popen`{.interpreted-text role="class"}. This means that *close_fds* now defaults to `True` on all supported platforms. (Contributed by Segev Finer in `19764`{.interpreted-text role="issue"}.)
The subprocess module is now more graceful when handling `KeyboardInterrupt`{.interpreted-text role="exc"} during `subprocess.call`{.interpreted-text role="func"}, `subprocess.run`{.interpreted-text role="func"}, or in a `~subprocess.Popen`{.interpreted-text role="class"} context manager. It now waits a short amount of time for the child to exit, before continuing the handling of the `KeyboardInterrupt` exception. (Contributed by Gregory P. Smith in `25942`{.interpreted-text role="issue"}.)
### sys
The new `sys.breakpointhook`{.interpreted-text role="func"} hook function is called by the built-in `breakpoint`{.interpreted-text role="func"}. (Contributed by Barry Warsaw in `31353`{.interpreted-text role="issue"}.)
On Android, the new `sys.getandroidapilevel`{.interpreted-text role="func"} returns the build-time Android API version. (Contributed by Victor Stinner in `28740`{.interpreted-text role="issue"}.)
The new `sys.get_coroutine_origin_tracking_depth`{.interpreted-text role="func"} function returns the current coroutine origin tracking depth, as set by the new `sys.set_coroutine_origin_tracking_depth`{.interpreted-text role="func"}. `asyncio`{.interpreted-text role="mod"} has been converted to use this new API instead of the deprecated `!sys.set_coroutine_wrapper`{.interpreted-text role="func"}. (Contributed by Nathaniel J. Smith in `32591`{.interpreted-text role="issue"}.)
### time
`564`{.interpreted-text role="pep"} adds six new functions with nanosecond resolution to the `time`{.interpreted-text role="mod"} module:
- `time.clock_gettime_ns`{.interpreted-text role="func"}
- `time.clock_settime_ns`{.interpreted-text role="func"}
- `time.monotonic_ns`{.interpreted-text role="func"}
- `time.perf_counter_ns`{.interpreted-text role="func"}
- `time.process_time_ns`{.interpreted-text role="func"}
- `time.time_ns`{.interpreted-text role="func"}
New clock identifiers have been added:
- `time.CLOCK_BOOTTIME`{.interpreted-text role="const"} (Linux): Identical to `time.CLOCK_MONOTONIC`{.interpreted-text role="const"}, except it also includes any time that the system is suspended.
- `time.CLOCK_PROF`{.interpreted-text role="const"} (FreeBSD, NetBSD and OpenBSD): High-resolution per-process CPU timer.
- `time.CLOCK_UPTIME`{.interpreted-text role="const"} (FreeBSD, OpenBSD): Time whose absolute value is the time the system has been running and not suspended, providing accurate uptime measurement.
The new `time.thread_time`{.interpreted-text role="func"} and `time.thread_time_ns`{.interpreted-text role="func"} functions can be used to get per-thread CPU time measurements. (Contributed by Antoine Pitrou in `32025`{.interpreted-text role="issue"}.)
The new `time.pthread_getcpuclockid`{.interpreted-text role="func"} function returns the clock ID of the thread-specific CPU-time clock.
### tkinter
The new `tkinter.ttk.Spinbox`{.interpreted-text role="class"} class is now available. (Contributed by Alan Moore in `32585`{.interpreted-text role="issue"}.)
### tracemalloc
`tracemalloc.Traceback`{.interpreted-text role="class"} behaves more like regular tracebacks, sorting the frames from oldest to most recent. `Traceback.format() <tracemalloc.Traceback.format>`{.interpreted-text role="meth"} now accepts negative *limit*, truncating the result to the `abs(limit)` oldest frames. To get the old behaviour, use the new *most_recent_first* argument to `Traceback.format()`. (Contributed by Jesse Bakker in `32121`{.interpreted-text role="issue"}.)
### types
The new `~types.WrapperDescriptorType`{.interpreted-text role="class"}, `~types.MethodWrapperType`{.interpreted-text role="class"}, `~types.MethodDescriptorType`{.interpreted-text role="class"}, and `~types.ClassMethodDescriptorType`{.interpreted-text role="class"} classes are now available. (Contributed by Manuel Krebber and Guido van Rossum in `29377`{.interpreted-text role="issue"}, and Serhiy Storchaka in `32265`{.interpreted-text role="issue"}.)
The new `types.resolve_bases`{.interpreted-text role="func"} function resolves MRO entries dynamically as specified by `560`{.interpreted-text role="pep"}. (Contributed by Ivan Levkivskyi in `32717`{.interpreted-text role="issue"}.)
### unicodedata
The internal `unicodedata`{.interpreted-text role="mod"} database has been upgraded to use [Unicode 11](https://www.unicode.org/versions/Unicode11.0.0/). (Contributed by Benjamin Peterson.)
### unittest
The new `-k` command-line option allows filtering tests by a name substring or a Unix shell-like pattern. For example, `python -m unittest -k foo` runs `foo_tests.SomeTest.test_something`, `bar_tests.SomeTest.test_foo`, but not `bar_tests.FooTest.test_something`. (Contributed by Jonas Haag in `32071`{.interpreted-text role="issue"}.)
### unittest.mock
The `~unittest.mock.sentinel`{.interpreted-text role="const"} attributes now preserve their identity when they are `copied <copy>`{.interpreted-text role="mod"} or `pickled <pickle>`{.interpreted-text role="mod"}. (Contributed by Serhiy Storchaka in `20804`{.interpreted-text role="issue"}.)
The new `~unittest.mock.seal`{.interpreted-text role="func"} function allows sealing `~unittest.mock.Mock`{.interpreted-text role="class"} instances, which will disallow further creation of attribute mocks. The seal is applied recursively to all attributes that are themselves mocks. (Contributed by Mario Corchero in `30541`{.interpreted-text role="issue"}.)
### urllib.parse
`urllib.parse.quote`{.interpreted-text role="func"} has been updated from `2396`{.interpreted-text role="rfc"} to `3986`{.interpreted-text role="rfc"}, adding `~` to the set of characters that are never quoted by default. (Contributed by Christian Theune and Ratnadeep Debnath in `16285`{.interpreted-text role="issue"}.)
### uu
The `!uu.encode`{.interpreted-text role="func"} function now accepts an optional *backtick* keyword argument. When it\'s true, zeros are represented by `` '`' `` instead of spaces. (Contributed by Xiang Zhang in `30103`{.interpreted-text role="issue"}.)
### uuid
The new `UUID.is_safe <uuid.UUID.is_safe>`{.interpreted-text role="attr"} attribute relays information from the platform about whether generated UUIDs are generated with a multiprocessing-safe method. (Contributed by Barry Warsaw in `22807`{.interpreted-text role="issue"}.)
`uuid.getnode`{.interpreted-text role="func"} now prefers universally administered MAC addresses over locally administered MAC addresses. This makes a better guarantee for global uniqueness of UUIDs returned from `uuid.uuid1`{.interpreted-text role="func"}. If only locally administered MAC addresses are available, the first such one found is returned. (Contributed by Barry Warsaw in `32107`{.interpreted-text role="issue"}.)
### warnings
The initialization of the default warnings filters has changed as follows:
- warnings enabled via command line options (including those for `-b`{.interpreted-text role="option"} and the new CPython-specific `-X`{.interpreted-text role="option"} `dev` option) are always passed to the warnings machinery via the `sys.warnoptions`{.interpreted-text role="data"} attribute.
- warnings filters enabled via the command line or the environment now have the following order of precedence:
- the `BytesWarning` filter for `-b`{.interpreted-text role="option"} (or `-bb`)
- any filters specified with the `-W`{.interpreted-text role="option"} option
- any filters specified with the `PYTHONWARNINGS`{.interpreted-text role="envvar"} environment variable
- any other CPython specific filters (e.g. the `default` filter added for the new `-X dev` mode)
- any implicit filters defined directly by the warnings machinery
- in `CPython debug builds <debug-build>`{.interpreted-text role="ref"}, all warnings are now displayed by default (the implicit filter list is empty)
(Contributed by Nick Coghlan and Victor Stinner in `20361`{.interpreted-text role="issue"}, `32043`{.interpreted-text role="issue"}, and `32230`{.interpreted-text role="issue"}.)
Deprecation warnings are once again shown by default in single-file scripts and at the interactive prompt. See `whatsnew37-pep565`{.interpreted-text role="ref"} for details. (Contributed by Nick Coghlan in `31975`{.interpreted-text role="issue"}.)
### xml
As mitigation against DTD and external entity retrieval, the `xml.dom.minidom`{.interpreted-text role="mod"} and `xml.sax`{.interpreted-text role="mod"} modules no longer process external entities by default. (Contributed by Christian Heimes in `61441`{.interpreted-text role="gh"}.)
### xml.etree
`ElementPath <elementtree-xpath>`{.interpreted-text role="ref"} predicates in the `!find`{.interpreted-text role="meth"} methods can now compare text of the current node with `[. = "text"]`, not only text in children. Predicates also allow adding spaces for better readability. (Contributed by Stefan Behnel in `31648`{.interpreted-text role="issue"}.)
### xmlrpc.server
`!SimpleXMLRPCDispatcher.register_function`{.interpreted-text role="meth"} can now be used as a decorator. (Contributed by Xiang Zhang in `7769`{.interpreted-text role="issue"}.)
### zipapp
Function `~zipapp.create_archive`{.interpreted-text role="func"} now accepts an optional *filter* argument to allow the user to select which files should be included in the archive. (Contributed by Irmen de Jong in `31072`{.interpreted-text role="issue"}.)
Function `~zipapp.create_archive`{.interpreted-text role="func"} now accepts an optional *compressed* argument to generate a compressed archive. A command line option `--compress` has also been added to support compression. (Contributed by Zhiming Wang in `31638`{.interpreted-text role="issue"}.)
### zipfile
`~zipfile.ZipFile`{.interpreted-text role="class"} now accepts the new *compresslevel* parameter to control the compression level. (Contributed by Bo Bayles in `21417`{.interpreted-text role="issue"}.)
Subdirectories in archives created by `ZipFile` are now stored in alphabetical order. (Contributed by Bernhard M. Wiedemann in `30693`{.interpreted-text role="issue"}.)
## C API Changes
A new API for thread-local storage has been implemented. See `whatsnew37-pep539`{.interpreted-text role="ref"} for an overview and `thread-specific-storage-api`{.interpreted-text role="ref"} for a complete reference. (Contributed by Masayuki Yamamoto in `25658`{.interpreted-text role="issue"}.)
The new `context variables <whatsnew37-pep567>`{.interpreted-text role="ref"} functionality exposes a number of `new C APIs <contextvarsobjects>`{.interpreted-text role="ref"}.
The new `PyImport_GetModule`{.interpreted-text role="c:func"} function returns the previously imported module with the given name. (Contributed by Eric Snow in `28411`{.interpreted-text role="issue"}.)
The new `Py_RETURN_RICHCOMPARE`{.interpreted-text role="c:macro"} macro eases writing rich comparison functions. (Contributed by Petr Victorin in `23699`{.interpreted-text role="issue"}.)
The new `Py_UNREACHABLE`{.interpreted-text role="c:macro"} macro can be used to mark unreachable code paths. (Contributed by Barry Warsaw in `31338`{.interpreted-text role="issue"}.)
The `tracemalloc`{.interpreted-text role="mod"} now exposes a C API through the new `PyTraceMalloc_Track`{.interpreted-text role="c:func"} and `PyTraceMalloc_Untrack`{.interpreted-text role="c:func"} functions. (Contributed by Victor Stinner in `30054`{.interpreted-text role="issue"}.)
The new `import__find__load__start <static-markers>`{.interpreted-text role="ref"} and `import__find__load__done <static-markers>`{.interpreted-text role="ref"} static markers can be used to trace module imports. (Contributed by Christian Heimes in `31574`{.interpreted-text role="issue"}.)
The fields `!name`{.interpreted-text role="c:member"} and `!doc`{.interpreted-text role="c:member"} of structures `PyMemberDef`{.interpreted-text role="c:type"}, `PyGetSetDef`{.interpreted-text role="c:type"}, `PyStructSequence_Field`{.interpreted-text role="c:type"}, `PyStructSequence_Desc`{.interpreted-text role="c:type"}, and `!wrapperbase`{.interpreted-text role="c:struct"} are now of type `const char *` rather of `char *`. (Contributed by Serhiy Storchaka in `28761`{.interpreted-text role="issue"}.)
The result of `PyUnicode_AsUTF8AndSize`{.interpreted-text role="c:func"} and `PyUnicode_AsUTF8`{.interpreted-text role="c:func"} is now of type `const char *` rather of `char *`. (Contributed by Serhiy Storchaka in `28769`{.interpreted-text role="issue"}.)
The result of `PyMapping_Keys`{.interpreted-text role="c:func"}, `PyMapping_Values`{.interpreted-text role="c:func"} and `PyMapping_Items`{.interpreted-text role="c:func"} is now always a list, rather than a list or a tuple. (Contributed by Oren Milman in `28280`{.interpreted-text role="issue"}.)
Added functions `PySlice_Unpack`{.interpreted-text role="c:func"} and `PySlice_AdjustIndices`{.interpreted-text role="c:func"}. (Contributed by Serhiy Storchaka in `27867`{.interpreted-text role="issue"}.)
`PyOS_AfterFork`{.interpreted-text role="c:func"} is deprecated in favour of the new functions `PyOS_BeforeFork`{.interpreted-text role="c:func"}, `PyOS_AfterFork_Parent`{.interpreted-text role="c:func"} and `PyOS_AfterFork_Child`{.interpreted-text role="c:func"}. (Contributed by Antoine Pitrou in `16500`{.interpreted-text role="issue"}.)
The `PyExc_RecursionErrorInst` singleton that was part of the public API has been removed as its members being never cleared may cause a segfault during finalization of the interpreter. Contributed by Xavier de Gaye in `22898`{.interpreted-text role="issue"} and `30697`{.interpreted-text role="issue"}.
Added C API support for timezones with timezone constructors `PyTimeZone_FromOffset`{.interpreted-text role="c:func"} and `PyTimeZone_FromOffsetAndName`{.interpreted-text role="c:func"}, and access to the UTC singleton with `PyDateTime_TimeZone_UTC`{.interpreted-text role="c:data"}. Contributed by Paul Ganssle in `10381`{.interpreted-text role="issue"}.
The type of results of `!PyThread_start_new_thread`{.interpreted-text role="c:func"} and `!PyThread_get_thread_ident`{.interpreted-text role="c:func"}, and the *id* parameter of `PyThreadState_SetAsyncExc`{.interpreted-text role="c:func"} changed from `long`{.interpreted-text role="c:expr"} to `unsigned long`{.interpreted-text role="c:expr"}. (Contributed by Serhiy Storchaka in `6532`{.interpreted-text role="issue"}.)
`PyUnicode_AsWideCharString`{.interpreted-text role="c:func"} now raises a `ValueError`{.interpreted-text role="exc"} if the second argument is `NULL` and the `wchar_t*`{.interpreted-text role="c:expr"} string contains null characters. (Contributed by Serhiy Storchaka in `30708`{.interpreted-text role="issue"}.)
Changes to the startup sequence and the management of dynamic memory allocators mean that the long documented requirement to call `Py_Initialize`{.interpreted-text role="c:func"} before calling most C API functions is now relied on more heavily, and failing to abide by it may lead to segfaults in embedding applications. See the `porting-to-python-37`{.interpreted-text role="ref"} section in this document and the `pre-init-safe`{.interpreted-text role="ref"} section in the C API documentation for more details.
The new `PyInterpreterState_GetID`{.interpreted-text role="c:func"} returns the unique ID for a given interpreter. (Contributed by Eric Snow in `29102`{.interpreted-text role="issue"}.)
`Py_DecodeLocale`{.interpreted-text role="c:func"}, `Py_EncodeLocale`{.interpreted-text role="c:func"} now use the UTF-8 encoding when the `UTF-8 mode <whatsnew37-pep540>`{.interpreted-text role="ref"} is enabled. (Contributed by Victor Stinner in `29240`{.interpreted-text role="issue"}.)
`PyUnicode_DecodeLocaleAndSize`{.interpreted-text role="c:func"} and `PyUnicode_EncodeLocale`{.interpreted-text role="c:func"} now use the current locale encoding for `surrogateescape` error handler. (Contributed by Victor Stinner in `29240`{.interpreted-text role="issue"}.)
The *start* and *end* parameters of `PyUnicode_FindChar`{.interpreted-text role="c:func"} are now adjusted to behave like string slices. (Contributed by Xiang Zhang in `28822`{.interpreted-text role="issue"}.)
## Build Changes
Support for building `--without-threads` has been removed. The `threading`{.interpreted-text role="mod"} module is now always available. (Contributed by Antoine Pitrou in `31370`{.interpreted-text role="issue"}.).
A full copy of libffi is no longer bundled for use when building the `_ctypes <ctypes>`{.interpreted-text role="mod"} module on non-OSX UNIX platforms. An installed copy of libffi is now required when building `_ctypes` on such platforms. (Contributed by Zachary Ware in `27979`{.interpreted-text role="issue"}.)
The Windows build process no longer depends on Subversion to pull in external sources, a Python script is used to download zipfiles from GitHub instead. If Python 3.6 is not found on the system (via `py -3.6`), NuGet is used to download a copy of 32-bit Python for this purpose. (Contributed by Zachary Ware in `30450`{.interpreted-text role="issue"}.)
The `ssl`{.interpreted-text role="mod"} module requires OpenSSL 1.0.2 or 1.1 compatible libssl. OpenSSL 1.0.1 has reached end of lifetime on 2016-12-31 and is no longer supported. LibreSSL is temporarily not supported as well. LibreSSL releases up to version 2.6.4 are missing required OpenSSL 1.0.2 APIs.
## Optimizations {#whatsnew37-perf}
The overhead of calling many methods of various standard library classes implemented in C has been significantly reduced by porting more code to use the `METH_FASTCALL` convention. (Contributed by Victor Stinner in `29300`{.interpreted-text role="issue"}, `29507`{.interpreted-text role="issue"}, `29452`{.interpreted-text role="issue"}, and `29286`{.interpreted-text role="issue"}.)
Various optimizations have reduced Python startup time by 10% on Linux and up to 30% on macOS. (Contributed by Victor Stinner, INADA Naoki in `29585`{.interpreted-text role="issue"}, and Ivan Levkivskyi in `31333`{.interpreted-text role="issue"}.)
Method calls are now up to 20% faster due to the bytecode changes which avoid creating bound method instances. (Contributed by Yury Selivanov and INADA Naoki in `26110`{.interpreted-text role="issue"}.)
::: {#whatsnew37-asyncio-perf}
The `asyncio`{.interpreted-text role="mod"} module received a number of notable optimizations for commonly used functions:
:::
- The `asyncio.get_event_loop`{.interpreted-text role="func"} function has been reimplemented in C to make it up to 15 times faster. (Contributed by Yury Selivanov in `32296`{.interpreted-text role="issue"}.)
- `asyncio.Future`{.interpreted-text role="class"} callback management has been optimized. (Contributed by Yury Selivanov in `32348`{.interpreted-text role="issue"}.)
- `asyncio.gather`{.interpreted-text role="func"} is now up to 15% faster. (Contributed by Yury Selivanov in `32355`{.interpreted-text role="issue"}.)
- `asyncio.sleep`{.interpreted-text role="func"} is now up to 2 times faster when the *delay* argument is zero or negative. (Contributed by Andrew Svetlov in `32351`{.interpreted-text role="issue"}.)
- The performance overhead of asyncio debug mode has been reduced. (Contributed by Antoine Pitrou in `31970`{.interpreted-text role="issue"}.)
As a result of `PEP 560 work <whatsnew37-pep560>`{.interpreted-text role="ref"}, the import time of `typing`{.interpreted-text role="mod"} has been reduced by a factor of 7, and many typing operations are now faster. (Contributed by Ivan Levkivskyi in `32226`{.interpreted-text role="issue"}.)
`sorted`{.interpreted-text role="func"} and `list.sort`{.interpreted-text role="meth"} have been optimized for common cases to be up to 40-75% faster. (Contributed by Elliot Gorokhovsky in `28685`{.interpreted-text role="issue"}.)
`dict.copy`{.interpreted-text role="meth"} is now up to 5.5 times faster. (Contributed by Yury Selivanov in `31179`{.interpreted-text role="issue"}.)
`hasattr`{.interpreted-text role="func"} and `getattr`{.interpreted-text role="func"} are now about 4 times faster when *name* is not found and *obj* does not override `object.__getattr__`{.interpreted-text role="meth"} or `object.__getattribute__`{.interpreted-text role="meth"}. (Contributed by INADA Naoki in `32544`{.interpreted-text role="issue"}.)
Searching for certain Unicode characters (like Ukrainian capital \"Є\") in a string was up to 25 times slower than searching for other characters. It is now only 3 times slower in the worst case. (Contributed by Serhiy Storchaka in `24821`{.interpreted-text role="issue"}.)
The `collections.namedtuple`{.interpreted-text role="func"} factory has been reimplemented to make the creation of named tuples 4 to 6 times faster. (Contributed by Jelle Zijlstra with further improvements by INADA Naoki, Serhiy Storchaka, and Raymond Hettinger in `28638`{.interpreted-text role="issue"}.)
`datetime.date.fromordinal`{.interpreted-text role="meth"} and `datetime.date.fromtimestamp`{.interpreted-text role="meth"} are now up to 30% faster in the common case. (Contributed by Paul Ganssle in `32403`{.interpreted-text role="issue"}.)
The `os.fwalk`{.interpreted-text role="func"} function is now up to 2 times faster thanks to the use of `os.scandir`{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in `25996`{.interpreted-text role="issue"}.)
The speed of the `shutil.rmtree`{.interpreted-text role="func"} function has been improved by 20\--40% thanks to the use of the `os.scandir`{.interpreted-text role="func"} function. (Contributed by Serhiy Storchaka in `28564`{.interpreted-text role="issue"}.)
Optimized case-insensitive matching and searching of `regular
expressions <re>`{.interpreted-text role="mod"}. Searching some patterns can now be up to 20 times faster. (Contributed by Serhiy Storchaka in `30285`{.interpreted-text role="issue"}.)
`re.compile`{.interpreted-text role="func"} now converts `flags` parameter to int object if it is `RegexFlag`. It is now as fast as Python 3.5, and faster than Python 3.6 by about 10% depending on the pattern. (Contributed by INADA Naoki in `31671`{.interpreted-text role="issue"}.)
The `~selectors.BaseSelector.modify`{.interpreted-text role="meth"} methods of classes `selectors.EpollSelector`{.interpreted-text role="class"}, `selectors.PollSelector`{.interpreted-text role="class"} and `selectors.DevpollSelector`{.interpreted-text role="class"} may be around 10% faster under heavy loads. (Contributed by Giampaolo Rodola\' in `30014`{.interpreted-text role="issue"})
Constant folding has been moved from the peephole optimizer to the new AST optimizer, which is able perform optimizations more consistently. (Contributed by Eugene Toder and INADA Naoki in `29469`{.interpreted-text role="issue"} and `11549`{.interpreted-text role="issue"}.)
Most functions and methods in `abc`{.interpreted-text role="mod"} have been rewritten in C. This makes creation of abstract base classes, and calling `isinstance`{.interpreted-text role="func"} and `issubclass`{.interpreted-text role="func"} on them 1.5x faster. This also reduces Python start-up time by up to 10%. (Contributed by Ivan Levkivskyi and INADA Naoki in `31333`{.interpreted-text role="issue"})
Significant speed improvements to alternate constructors for `datetime.date`{.interpreted-text role="class"} and `datetime.datetime`{.interpreted-text role="class"} by using fast-path constructors when not constructing subclasses. (Contributed by Paul Ganssle in `32403`{.interpreted-text role="issue"})
The speed of comparison of `array.array`{.interpreted-text role="class"} instances has been improved considerably in certain cases. It is now from 10x to 70x faster when comparing arrays holding values of the same integer type. (Contributed by Adrian Wielgosik in `24700`{.interpreted-text role="issue"}.)
The `math.erf`{.interpreted-text role="func"} and `math.erfc`{.interpreted-text role="func"} functions now use the (faster) C library implementation on most platforms. (Contributed by Serhiy Storchaka in `26121`{.interpreted-text role="issue"}.)
## Other CPython Implementation Changes
- Trace hooks may now opt out of receiving the `line` and opt into receiving the `opcode` events from the interpreter by setting the corresponding new `~frame.f_trace_lines`{.interpreted-text role="attr"} and `~frame.f_trace_opcodes`{.interpreted-text role="attr"} attributes on the frame being traced. (Contributed by Nick Coghlan in `31344`{.interpreted-text role="issue"}.)
- Fixed some consistency problems with namespace package module attributes. Namespace module objects now have an `__file__` that is set to `None` (previously unset), and their `__spec__.origin` is also set to `None` (previously the string `"namespace"`). See `32305`{.interpreted-text role="issue"}. Also, the namespace module object\'s `__spec__.loader` is set to the same value as `__loader__` (previously, the former was set to `None`). See `32303`{.interpreted-text role="issue"}.
- The `locals`{.interpreted-text role="func"} dictionary now displays in the lexical order that variables were defined. Previously, the order was undefined. (Contributed by Raymond Hettinger in `32690`{.interpreted-text role="issue"}.)
- The `distutils` `upload` command no longer tries to change CR end-of-line characters to CRLF. This fixes a corruption issue with sdists that ended with a byte equivalent to CR. (Contributed by Bo Bayles in `32304`{.interpreted-text role="issue"}.)
## Deprecated Python Behavior
Yield expressions (both `yield` and `yield from` clauses) are now deprecated in comprehensions and generator expressions (aside from the iterable expression in the leftmost `!for`{.interpreted-text role="keyword"} clause). This ensures that comprehensions always immediately return a container of the appropriate type (rather than potentially returning a `generator iterator`{.interpreted-text role="term"} object), while generator expressions won\'t attempt to interleave their implicit output with the output from any explicit yield expressions. In Python 3.7, such expressions emit `DeprecationWarning`{.interpreted-text role="exc"} when compiled, in Python 3.8 this will be a `SyntaxError`{.interpreted-text role="exc"}. (Contributed by Serhiy Storchaka in `10544`{.interpreted-text role="issue"}.)
Returning a subclass of `complex`{.interpreted-text role="class"} from `object.__complex__`{.interpreted-text role="meth"} is deprecated and will be an error in future Python versions. This makes `__complex__()` consistent with `object.__int__`{.interpreted-text role="meth"} and `object.__float__`{.interpreted-text role="meth"}. (Contributed by Serhiy Storchaka in `28894`{.interpreted-text role="issue"}.)
## Deprecated Python modules, functions and methods
### aifc
`!aifc.openfp`{.interpreted-text role="func"} has been deprecated and will be removed in Python 3.9. Use `!aifc.open`{.interpreted-text role="func"} instead. (Contributed by Brian Curtin in `31985`{.interpreted-text role="issue"}.)
### asyncio {#whatsnew37-asyncio-deprecated}
Support for directly `await`-ing instances of `asyncio.Lock`{.interpreted-text role="class"} and other asyncio synchronization primitives has been deprecated. An asynchronous context manager must be used in order to acquire and release the synchronization resource. (Contributed by Andrew Svetlov in `32253`{.interpreted-text role="issue"}.)
The `!asyncio.Task.current_task`{.interpreted-text role="meth"} and `!asyncio.Task.all_tasks`{.interpreted-text role="meth"} methods have been deprecated. (Contributed by Andrew Svetlov in `32250`{.interpreted-text role="issue"}.)
### collections
In Python 3.8, the abstract base classes in `collections.abc`{.interpreted-text role="mod"} will no longer be exposed in the regular `collections`{.interpreted-text role="mod"} module. This will help create a clearer distinction between the concrete classes and the abstract base classes. (Contributed by Serhiy Storchaka in `25988`{.interpreted-text role="issue"}.)
### dbm
`dbm.dumb`{.interpreted-text role="mod"} now supports reading read-only files and no longer writes the index file when it is not changed. A deprecation warning is now emitted if the index file is missing and recreated in the `'r'` and `'w'` modes (this will be an error in future Python releases). (Contributed by Serhiy Storchaka in `28847`{.interpreted-text role="issue"}.)
### enum
In Python 3.8, attempting to check for non-Enum objects in `~enum.Enum`{.interpreted-text role="class"} classes will raise a `TypeError`{.interpreted-text role="exc"} (e.g. `1 in Color`); similarly, attempting to check for non-Flag objects in a `~enum.Flag`{.interpreted-text role="class"} member will raise `TypeError`{.interpreted-text role="exc"} (e.g. `1 in Perm.RW`); currently, both operations return `False`{.interpreted-text role="const"} instead. (Contributed by Ethan Furman in `33217`{.interpreted-text role="issue"}.)
### gettext
Using non-integer value for selecting a plural form in `gettext`{.interpreted-text role="mod"} is now deprecated. It never correctly worked. (Contributed by Serhiy Storchaka in `28692`{.interpreted-text role="issue"}.)
### importlib
Methods `!MetaPathFinder.find_module`{.interpreted-text role="meth"} (replaced by `MetaPathFinder.find_spec() <importlib.abc.MetaPathFinder.find_spec>`{.interpreted-text role="meth"}) and `!PathEntryFinder.find_loader`{.interpreted-text role="meth"} (replaced by `PathEntryFinder.find_spec() <importlib.abc.PathEntryFinder.find_spec>`{.interpreted-text role="meth"}) both deprecated in Python 3.4 now emit `DeprecationWarning`{.interpreted-text role="exc"}. (Contributed by Matthias Bussonnier in `29576`{.interpreted-text role="issue"}.)
The `importlib.abc.ResourceLoader`{.interpreted-text role="class"} ABC has been deprecated in favour of `!importlib.abc.ResourceReader`{.interpreted-text role="class"}.
### locale
`!locale.format`{.interpreted-text role="func"} has been deprecated, use `locale.format_string`{.interpreted-text role="meth"} instead. (Contributed by Garvit in `10379`{.interpreted-text role="issue"}.)
### macpath
The `!macpath`{.interpreted-text role="mod"} is now deprecated and will be removed in Python 3.8. (Contributed by Chi Hsuan Yen in `9850`{.interpreted-text role="issue"}.)
### threading
`!dummy_threading`{.interpreted-text role="mod"} and `!_dummy_thread`{.interpreted-text role="mod"} have been deprecated. It is no longer possible to build Python with threading disabled. Use `threading`{.interpreted-text role="mod"} instead. (Contributed by Antoine Pitrou in `31370`{.interpreted-text role="issue"}.)
### socket
The silent argument value truncation in `socket.htons`{.interpreted-text role="func"} and `socket.ntohs`{.interpreted-text role="func"} has been deprecated. In future versions of Python, if the passed argument is larger than 16 bits, an exception will be raised. (Contributed by Oren Milman in `28332`{.interpreted-text role="issue"}.)
### ssl
`!ssl.wrap_socket`{.interpreted-text role="func"} is deprecated. Use `ssl.SSLContext.wrap_socket`{.interpreted-text role="meth"} instead. (Contributed by Christian Heimes in `28124`{.interpreted-text role="issue"}.)
### sunau
`!sunau.openfp`{.interpreted-text role="func"} has been deprecated and will be removed in Python 3.9. Use `!sunau.open`{.interpreted-text role="func"} instead. (Contributed by Brian Curtin in `31985`{.interpreted-text role="issue"}.)
### sys
Deprecated `!sys.set_coroutine_wrapper`{.interpreted-text role="func"} and `!sys.get_coroutine_wrapper`{.interpreted-text role="func"}.
The undocumented `sys.callstats()` function has been deprecated and will be removed in a future Python version. (Contributed by Victor Stinner in `28799`{.interpreted-text role="issue"}.)
### wave
`!wave.openfp`{.interpreted-text role="func"} has been deprecated and will be removed in Python 3.9. Use `wave.open`{.interpreted-text role="func"} instead. (Contributed by Brian Curtin in `31985`{.interpreted-text role="issue"}.)
## Deprecated functions and types of the C API
Function `PySlice_GetIndicesEx`{.interpreted-text role="c:func"} is deprecated and replaced with a macro if `Py_LIMITED_API` is not set or set to a value in the range between `0x03050400` and `0x03060000` (not inclusive), or is `0x03060100` or higher. (Contributed by Serhiy Storchaka in `27867`{.interpreted-text role="issue"}.)
`PyOS_AfterFork`{.interpreted-text role="c:func"} has been deprecated. Use `PyOS_BeforeFork`{.interpreted-text role="c:func"}, `PyOS_AfterFork_Parent`{.interpreted-text role="c:func"} or `PyOS_AfterFork_Child()`{.interpreted-text role="c:func"} instead. (Contributed by Antoine Pitrou in `16500`{.interpreted-text role="issue"}.)
## Platform Support Removals {#37-platform-support-removals}
- FreeBSD 9 and older are no longer officially supported.
- For full Unicode support, including within extension modules, \*nix platforms are now expected to provide at least one of `C.UTF-8` (full locale), `C.utf8` (full locale) or `UTF-8` (`LC_CTYPE`-only locale) as an alternative to the legacy `ASCII`-based `C` locale.
- OpenSSL 0.9.8 and 1.0.1 are no longer supported, which means building CPython 3.7 with SSL/TLS support on older platforms still using these versions requires custom build options that link to a more recent version of OpenSSL.
Notably, this issue affects the Debian 8 (aka \"jessie\") and Ubuntu 14.04 (aka \"Trusty\") LTS Linux distributions, as they still use OpenSSL 1.0.1 by default.
Debian 9 (\"stretch\") and Ubuntu 16.04 (\"xenial\"), as well as recent releases of other LTS Linux releases (e.g. RHEL/CentOS 7.5, SLES 12-SP3), use OpenSSL 1.0.2 or later, and remain supported in the default build configuration.
CPython\'s own [CI configuration file](https://github.com/python/cpython/blob/v3.7.13/.travis.yml) provides an example of using the SSL `compatibility testing infrastructure <Tools/ssl/multissltests.py>`{.interpreted-text role="source"} in CPython\'s test suite to build and link against OpenSSL 1.1.0 rather than an outdated system provided OpenSSL.
## API and Feature Removals
The following features and APIs have been removed from Python 3.7:
- The `os.stat_float_times()` function has been removed. It was introduced in Python 2.3 for backward compatibility with Python 2.2, and was deprecated since Python 3.1.
- Unknown escapes consisting of `'\'` and an ASCII letter in replacement templates for `re.sub`{.interpreted-text role="func"} were deprecated in Python 3.5, and will now cause an error.
- Removed support of the *exclude* argument in `tarfile.TarFile.add`{.interpreted-text role="meth"}. It was deprecated in Python 2.7 and 3.2. Use the *filter* argument instead.
- The `!ntpath.splitunc`{.interpreted-text role="func"} function was deprecated in Python 3.1, and has now been removed. Use `~os.path.splitdrive`{.interpreted-text role="func"} instead.
- `collections.namedtuple`{.interpreted-text role="func"} no longer supports the *verbose* parameter or `_source` attribute which showed the generated source code for the named tuple class. This was part of an optimization designed to speed-up class creation. (Contributed by Jelle Zijlstra with further improvements by INADA Naoki, Serhiy Storchaka, and Raymond Hettinger in `28638`{.interpreted-text role="issue"}.)
- Functions `bool`{.interpreted-text role="func"}, `float`{.interpreted-text role="func"}, `list`{.interpreted-text role="func"} and `tuple`{.interpreted-text role="func"} no longer take keyword arguments. The first argument of `int`{.interpreted-text role="func"} can now be passed only as positional argument.
- Removed previously deprecated in Python 2.4 classes `Plist`, `Dict` and `_InternalDict` in the `plistlib`{.interpreted-text role="mod"} module. Dict values in the result of functions `!readPlist`{.interpreted-text role="func"} and `!readPlistFromBytes`{.interpreted-text role="func"} are now normal dicts. You no longer can use attribute access to access items of these dictionaries.
- The `asyncio.windows_utils.socketpair()` function has been removed. Use the `socket.socketpair`{.interpreted-text role="func"} function instead, it is available on all platforms since Python 3.5. `asyncio.windows_utils.socketpair` was just an alias to `socket.socketpair` on Python 3.5 and newer.
- `asyncio`{.interpreted-text role="mod"} no longer exports the `selectors`{.interpreted-text role="mod"} and `!_overlapped`{.interpreted-text role="mod"} modules as `asyncio.selectors` and `asyncio._overlapped`. Replace `from asyncio import selectors` with `import selectors`.
- Direct instantiation of `ssl.SSLSocket`{.interpreted-text role="class"} and `ssl.SSLObject`{.interpreted-text role="class"} objects is now prohibited. The constructors were never documented, tested, or designed as public constructors. Users were supposed to use `!ssl.wrap_socket`{.interpreted-text role="func"} or `ssl.SSLContext`{.interpreted-text role="class"}. (Contributed by Christian Heimes in `32951`{.interpreted-text role="issue"}.)
- The unused `distutils` `install_misc` command has been removed. (Contributed by Eric N. Vander Weele in `29218`{.interpreted-text role="issue"}.)
## Module Removals
The `fpectl` module has been removed. It was never enabled by default, never worked correctly on x86-64, and it changed the Python ABI in ways that caused unexpected breakage of C extensions. (Contributed by Nathaniel J. Smith in `29137`{.interpreted-text role="issue"}.)
## Windows-only Changes
The python launcher, (py.exe), can accept 32 & 64 bit specifiers **without** having to specify a minor version as well. So `py -3-32` and `py -3-64` become valid as well as `py -3.7-32`, also the -*m*-64 and -*m.n*-64 forms are now accepted to force 64 bit python even if 32 bit would have otherwise been used. If the specified version is not available py.exe will error exit. (Contributed by Steve Barnes in `30291`{.interpreted-text role="issue"}.)
The launcher can be run as `py -0` to produce a list of the installed pythons, *with default marked with an asterisk*. Running `py -0p` will include the paths. If py is run with a version specifier that cannot be matched it will also print the *short form* list of available specifiers. (Contributed by Steve Barnes in `30362`{.interpreted-text role="issue"}.)
## Porting to Python 3.7 {#porting-to-python-37}
This section lists previously described changes and other bugfixes that may require changes to your code.
### Changes in Python Behavior
- `async`{.interpreted-text role="keyword"} and `await`{.interpreted-text role="keyword"} names are now reserved keywords. Code using these names as identifiers will now raise a `SyntaxError`{.interpreted-text role="exc"}. (Contributed by Jelle Zijlstra in `30406`{.interpreted-text role="issue"}.)
- `479`{.interpreted-text role="pep"} is enabled for all code in Python 3.7, meaning that `StopIteration`{.interpreted-text role="exc"} exceptions raised directly or indirectly in coroutines and generators are transformed into `RuntimeError`{.interpreted-text role="exc"} exceptions. (Contributed by Yury Selivanov in `32670`{.interpreted-text role="issue"}.)
- `object.__aiter__`{.interpreted-text role="meth"} methods can no longer be declared as asynchronous. (Contributed by Yury Selivanov in `31709`{.interpreted-text role="issue"}.)
- Due to an oversight, earlier Python versions erroneously accepted the following syntax:
f(1 for x in [1],)
class C(1 for x in [1]):
pass
Python 3.7 now correctly raises a `SyntaxError`{.interpreted-text role="exc"}, as a generator expression always needs to be directly inside a set of parentheses and cannot have a comma on either side, and the duplication of the parentheses can be omitted only on calls. (Contributed by Serhiy Storchaka in `32012`{.interpreted-text role="issue"} and `32023`{.interpreted-text role="issue"}.)
- When using the `-m`{.interpreted-text role="option"} switch, the initial working directory is now added to `sys.path`{.interpreted-text role="data"}, rather than an empty string (which dynamically denoted the current working directory at the time of each import). Any programs that are checking for the empty string, or otherwise relying on the previous behaviour, will need to be updated accordingly (e.g. by also checking for `os.getcwd()` or `os.path.dirname(__main__.__file__)`, depending on why the code was checking for the empty string in the first place).
### Changes in the Python API
- `socketserver.ThreadingMixIn.server_close
<socketserver.BaseServer.server_close>`{.interpreted-text role="meth"} now waits until all non-daemon threads complete. Set the new `socketserver.ThreadingMixIn.block_on_close`{.interpreted-text role="attr"} class attribute to `False` to get the pre-3.7 behaviour. (Contributed by Victor Stinner in `31233`{.interpreted-text role="issue"} and `33540`{.interpreted-text role="issue"}.)
- `socketserver.ForkingMixIn.server_close
<socketserver.BaseServer.server_close>`{.interpreted-text role="meth"} now waits until all child processes complete. Set the new `socketserver.ForkingMixIn.block_on_close
<socketserver.ThreadingMixIn.block_on_close>`{.interpreted-text role="attr"} class attribute to `False` to get the pre-3.7 behaviour. (Contributed by Victor Stinner in `31151`{.interpreted-text role="issue"} and `33540`{.interpreted-text role="issue"}.)
- The `locale.localeconv`{.interpreted-text role="func"} function now temporarily sets the `LC_CTYPE` locale to the value of `LC_NUMERIC` in some cases. (Contributed by Victor Stinner in `31900`{.interpreted-text role="issue"}.)
- `pkgutil.walk_packages`{.interpreted-text role="meth"} now raises a `ValueError`{.interpreted-text role="exc"} if *path* is a string. Previously an empty list was returned. (Contributed by Sanyam Khurana in `24744`{.interpreted-text role="issue"}.)
- A format string argument for `string.Formatter.format`{.interpreted-text role="meth"} is now `positional-only <positional-only_parameter>`{.interpreted-text role="ref"}. Passing it as a keyword argument was deprecated in Python 3.5. (Contributed by Serhiy Storchaka in `29193`{.interpreted-text role="issue"}.)
- Attributes `~http.cookies.Morsel.key`{.interpreted-text role="attr"}, `~http.cookies.Morsel.value`{.interpreted-text role="attr"} and `~http.cookies.Morsel.coded_value`{.interpreted-text role="attr"} of class `http.cookies.Morsel`{.interpreted-text role="class"} are now read-only. Assigning to them was deprecated in Python 3.5. Use the `~http.cookies.Morsel.set`{.interpreted-text role="meth"} method for setting them. (Contributed by Serhiy Storchaka in `29192`{.interpreted-text role="issue"}.)
- The *mode* argument of `os.makedirs`{.interpreted-text role="func"} no longer affects the file permission bits of newly created intermediate-level directories. To set their file permission bits you can set the umask before invoking `makedirs()`. (Contributed by Serhiy Storchaka in `19930`{.interpreted-text role="issue"}.)
- The `struct.Struct.format`{.interpreted-text role="attr"} type is now `str`{.interpreted-text role="class"} instead of `bytes`{.interpreted-text role="class"}. (Contributed by Victor Stinner in `21071`{.interpreted-text role="issue"}.)
- `!cgi.parse_multipart`{.interpreted-text role="func"} now accepts the *encoding* and *errors* arguments and returns the same results as `!FieldStorage`{.interpreted-text role="class"}: for non-file fields, the value associated to a key is a list of strings, not bytes. (Contributed by Pierre Quentel in `29979`{.interpreted-text role="issue"}.)
- Due to internal changes in `socket`{.interpreted-text role="mod"}, calling `socket.fromshare`{.interpreted-text role="func"} on a socket created by `socket.share <socket.socket.share>`{.interpreted-text role="func"} in older Python versions is not supported.
- `repr` for `BaseException`{.interpreted-text role="exc"} has changed to not include the trailing comma. Most exceptions are affected by this change. (Contributed by Serhiy Storchaka in `30399`{.interpreted-text role="issue"}.)
- `repr` for `datetime.timedelta`{.interpreted-text role="class"} has changed to include the keyword arguments in the output. (Contributed by Utkarsh Upadhyay in `30302`{.interpreted-text role="issue"}.)
- Because `shutil.rmtree`{.interpreted-text role="func"} is now implemented using the `os.scandir`{.interpreted-text role="func"} function, the user specified handler *onerror* is now called with the first argument `os.scandir` instead of `os.listdir` when listing the directory is failed.
- Support for nested sets and set operations in regular expressions as in [Unicode Technical Standard #18](https://unicode.org/reports/tr18/) might be added in the future. This would change the syntax. To facilitate this future change a `FutureWarning`{.interpreted-text role="exc"} will be raised in ambiguous cases for the time being. That include sets starting with a literal `'['` or containing literal character sequences `'--'`, `'&&'`, `'~~'`, and `'||'`. To avoid a warning, escape them with a backslash. (Contributed by Serhiy Storchaka in `30349`{.interpreted-text role="issue"}.)
- The result of splitting a string on a `regular expression <re>`{.interpreted-text role="mod"} that could match an empty string has been changed. For example splitting on `r'\s*'` will now split not only on whitespaces as it did previously, but also on empty strings before all non-whitespace characters and just before the end of the string. The previous behavior can be restored by changing the pattern to `r'\s+'`. A `FutureWarning`{.interpreted-text role="exc"} was emitted for such patterns since Python 3.5.
For patterns that match both empty and non-empty strings, the result of searching for all matches may also be changed in other cases. For example in the string `'a\n\n'`, the pattern `r'(?m)^\s*?$'` will not only match empty strings at positions 2 and 3, but also the string `'\n'` at positions 2\--3. To match only blank lines, the pattern should be rewritten as `r'(?m)^[^\S\n]*$'`.
`re.sub`{.interpreted-text role="func"} now replaces empty matches adjacent to a previous non-empty match. For example `re.sub('x*', '-', 'abxd')` returns now `'-a-b--d-'` instead of `'-a-b-d-'` (the first minus between \'b\' and \'d\' replaces \'x\', and the second minus replaces an empty string between \'x\' and \'d\').
(Contributed by Serhiy Storchaka in `25054`{.interpreted-text role="issue"} and `32308`{.interpreted-text role="issue"}.)
- Change `re.escape`{.interpreted-text role="func"} to only escape regex special characters instead of escaping all characters other than ASCII letters, numbers, and `'_'`. (Contributed by Serhiy Storchaka in `29995`{.interpreted-text role="issue"}.)
- `tracemalloc.Traceback`{.interpreted-text role="class"} frames are now sorted from oldest to most recent to be more consistent with `traceback`{.interpreted-text role="mod"}. (Contributed by Jesse Bakker in `32121`{.interpreted-text role="issue"}.)
- On OSes that support `socket.SOCK_NONBLOCK`{.interpreted-text role="const"} or `socket.SOCK_CLOEXEC`{.interpreted-text role="const"} bit flags, the `socket.type <socket.socket.type>`{.interpreted-text role="attr"} no longer has them applied. Therefore, checks like `if sock.type == socket.SOCK_STREAM` work as expected on all platforms. (Contributed by Yury Selivanov in `32331`{.interpreted-text role="issue"}.)
- On Windows the default for the *close_fds* argument of `subprocess.Popen`{.interpreted-text role="class"} was changed from `False`{.interpreted-text role="const"} to `True`{.interpreted-text role="const"} when redirecting the standard handles. If you previously depended on handles being inherited when using `subprocess.Popen`{.interpreted-text role="class"} with standard io redirection, you will have to pass `close_fds=False` to preserve the previous behaviour, or use `STARTUPINFO.lpAttributeList <subprocess.STARTUPINFO.lpAttributeList>`{.interpreted-text role="attr"}.
- `importlib.machinery.PathFinder.invalidate_caches`{.interpreted-text role="meth"} \-- which implicitly affects `importlib.invalidate_caches`{.interpreted-text role="func"} \-- now deletes entries in `sys.path_importer_cache`{.interpreted-text role="data"} which are set to `None`. (Contributed by Brett Cannon in `33169`{.interpreted-text role="issue"}.)
- In `asyncio`{.interpreted-text role="mod"}, `loop.sock_recv() <asyncio.loop.sock_recv>`{.interpreted-text role="meth"}, `loop.sock_sendall() <asyncio.loop.sock_sendall>`{.interpreted-text role="meth"}, `loop.sock_accept() <asyncio.loop.sock_accept>`{.interpreted-text role="meth"}, `loop.getaddrinfo() <asyncio.loop.getaddrinfo>`{.interpreted-text role="meth"}, `loop.getnameinfo() <asyncio.loop.getnameinfo>`{.interpreted-text role="meth"} have been changed to be proper coroutine methods to match their documentation. Previously, these methods returned `asyncio.Future`{.interpreted-text role="class"} instances. (Contributed by Yury Selivanov in `32327`{.interpreted-text role="issue"}.)
- `asyncio.Server.sockets`{.interpreted-text role="attr"} now returns a copy of the internal list of server sockets, instead of returning it directly. (Contributed by Yury Selivanov in `32662`{.interpreted-text role="issue"}.)
- `Struct.format <struct.Struct.format>`{.interpreted-text role="attr"} is now a `str`{.interpreted-text role="class"} instance instead of a `bytes`{.interpreted-text role="class"} instance. (Contributed by Victor Stinner in `21071`{.interpreted-text role="issue"}.)
- `argparse`{.interpreted-text role="mod"} subparsers can now be made mandatory by passing `required=True` to `ArgumentParser.add_subparsers() <argparse.ArgumentParser.add_subparsers>`{.interpreted-text role="meth"}. (Contributed by Anthony Sottile in `26510`{.interpreted-text role="issue"}.)
- `ast.literal_eval`{.interpreted-text role="meth"} is now stricter. Addition and subtraction of arbitrary numbers are no longer allowed. (Contributed by Serhiy Storchaka in `31778`{.interpreted-text role="issue"}.)
- `Calendar.itermonthdates <calendar.Calendar.itermonthdates>`{.interpreted-text role="meth"} will now consistently raise an exception when a date falls outside of the `0001-01-01` through `9999-12-31` range. To support applications that cannot tolerate such exceptions, the new `Calendar.itermonthdays3 <calendar.Calendar.itermonthdays3>`{.interpreted-text role="meth"} and `Calendar.itermonthdays4 <calendar.Calendar.itermonthdays4>`{.interpreted-text role="meth"} can be used. The new methods return tuples and are not restricted by the range supported by `datetime.date`{.interpreted-text role="class"}. (Contributed by Alexander Belopolsky in `28292`{.interpreted-text role="issue"}.)
- `collections.ChainMap`{.interpreted-text role="class"} now preserves the order of the underlying mappings. (Contributed by Raymond Hettinger in `32792`{.interpreted-text role="issue"}.)
- The `submit()` method of `concurrent.futures.ThreadPoolExecutor`{.interpreted-text role="class"} and `concurrent.futures.ProcessPoolExecutor`{.interpreted-text role="class"} now raises a `RuntimeError`{.interpreted-text role="exc"} if called during interpreter shutdown. (Contributed by Mark Nemec in `33097`{.interpreted-text role="issue"}.)
- The `configparser.ConfigParser`{.interpreted-text role="class"} constructor now uses `read_dict()` to process the default values, making its behavior consistent with the rest of the parser. Non-string keys and values in the defaults dictionary are now being implicitly converted to strings. (Contributed by James Tocknell in `23835`{.interpreted-text role="issue"}.)
- Several undocumented internal imports were removed. One example is that `os.errno` is no longer available; use `import errno` directly instead. Note that such undocumented internal imports may be removed any time without notice, even in micro version releases.
### Changes in the C API
The function `PySlice_GetIndicesEx`{.interpreted-text role="c:func"} is considered unsafe for resizable sequences. If the slice indices are not instances of `int`{.interpreted-text role="class"}, but objects that implement the `!__index__`{.interpreted-text role="meth"} method, the sequence can be resized after passing its length to `!PySlice_GetIndicesEx`{.interpreted-text role="c:func"}. This can lead to returning indices out of the length of the sequence. For avoiding possible problems use new functions `PySlice_Unpack`{.interpreted-text role="c:func"} and `PySlice_AdjustIndices`{.interpreted-text role="c:func"}. (Contributed by Serhiy Storchaka in `27867`{.interpreted-text role="issue"}.)
### CPython bytecode changes
There are two new opcodes: `!LOAD_METHOD`{.interpreted-text role="opcode"} and `!CALL_METHOD`{.interpreted-text role="opcode"}. (Contributed by Yury Selivanov and INADA Naoki in `26110`{.interpreted-text role="issue"}.)
The `!STORE_ANNOTATION`{.interpreted-text role="opcode"} opcode has been removed. (Contributed by Mark Shannon in `32550`{.interpreted-text role="issue"}.)
### Windows-only Changes
The file used to override `sys.path`{.interpreted-text role="data"} is now called `<python-executable>._pth` instead of `'sys.path'`. See `windows_finding_modules`{.interpreted-text role="ref"} for more information. (Contributed by Steve Dower in `28137`{.interpreted-text role="issue"}.)
### Other CPython implementation changes
In preparation for potential future changes to the public CPython runtime initialization API (see `432`{.interpreted-text role="pep"} for an initial, but somewhat outdated, draft), CPython\'s internal startup and configuration management logic has been significantly refactored. While these updates are intended to be entirely transparent to both embedding applications and users of the regular CPython CLI, they\'re being mentioned here as the refactoring changes the internal order of various operations during interpreter startup, and hence may uncover previously latent defects, either in embedding applications, or in CPython itself. (Initially contributed by Nick Coghlan and Eric Snow as part of `22257`{.interpreted-text role="issue"}, and further updated by Nick, Eric, and Victor Stinner in a number of other issues). Some known details affected:
- `!PySys_AddWarnOptionUnicode`{.interpreted-text role="c:func"} is not currently usable by embedding applications due to the requirement to create a Unicode object prior to calling `Py_Initialize`. Use `!PySys_AddWarnOption`{.interpreted-text role="c:func"} instead.
- warnings filters added by an embedding application with `!PySys_AddWarnOption`{.interpreted-text role="c:func"} should now more consistently take precedence over the default filters set by the interpreter
Due to changes in the way the default warnings filters are configured, setting `Py_BytesWarningFlag`{.interpreted-text role="c:data"} to a value greater than one is no longer sufficient to both emit `BytesWarning`{.interpreted-text role="exc"} messages and have them converted to exceptions. Instead, the flag must be set (to cause the warnings to be emitted in the first place), and an explicit `error::BytesWarning` warnings filter added to convert them to exceptions.
Due to a change in the way docstrings are handled by the compiler, the implicit `return None` in a function body consisting solely of a docstring is now marked as occurring on the same line as the docstring, not on the function\'s header line.
The current exception state has been moved from the frame object to the co-routine. This simplified the interpreter and fixed a couple of obscure bugs caused by having swap exception state when entering or exiting a generator. (Contributed by Mark Shannon in `25612`{.interpreted-text role="issue"}.)
## Notable changes in Python 3.7.1
Starting in 3.7.1, `Py_Initialize`{.interpreted-text role="c:func"} now consistently reads and respects all of the same environment settings as `Py_Main`{.interpreted-text role="c:func"} (in earlier Python versions, it respected an ill-defined subset of those environment variables, while in Python 3.7.0 it didn\'t read any of them due to `34247`{.interpreted-text role="issue"}). If this behavior is unwanted, set `Py_IgnoreEnvironmentFlag`{.interpreted-text role="c:data"} to 1 before calling `Py_Initialize`{.interpreted-text role="c:func"}.
In 3.7.1 the C API for Context Variables `was updated <contextvarsobjects_pointertype_change>`{.interpreted-text role="ref"} to use `PyObject`{.interpreted-text role="c:type"} pointers. See also `34762`{.interpreted-text role="issue"}.
In 3.7.1 the `tokenize`{.interpreted-text role="mod"} module now implicitly emits a `NEWLINE` token when provided with input that does not have a trailing new line. This behavior now matches what the C tokenizer does internally. (Contributed by Ammar Askar in `33899`{.interpreted-text role="issue"}.)
## Notable changes in Python 3.7.2
In 3.7.2, `venv`{.interpreted-text role="mod"} on Windows no longer copies the original binaries, but creates redirector scripts named `python.exe` and `pythonw.exe` instead. This resolves a long standing issue where all virtual environments would have to be upgraded or recreated with each Python update. However, note that this release will still require recreation of virtual environments in order to get the new scripts.
## Notable changes in Python 3.7.6
Due to significant security concerns, the *reuse_address* parameter of `asyncio.loop.create_datagram_endpoint`{.interpreted-text role="meth"} is no longer supported. This is because of the behavior of the socket option `SO_REUSEADDR` in UDP. For more details, see the documentation for `loop.create_datagram_endpoint()`. (Contributed by Kyle Stanley, Antoine Pitrou, and Yury Selivanov in `37228`{.interpreted-text role="issue"}.)
## Notable changes in Python 3.7.10
Earlier Python versions allowed using both `;` and `&` as query parameter separators in `urllib.parse.parse_qs`{.interpreted-text role="func"} and `urllib.parse.parse_qsl`{.interpreted-text role="func"}. Due to security concerns, and to conform with newer W3C recommendations, this has been changed to allow only a single separator key, with `&` as the default. This change also affects `!cgi.parse`{.interpreted-text role="func"} and `!cgi.parse_multipart`{.interpreted-text role="func"} as they use the affected functions internally. For more details, please see their respective documentation. (Contributed by Adam Goldschmidt, Senthil Kumaran and Ken Jin in `42967`{.interpreted-text role="issue"}.)
## Notable changes in Python 3.7.11
A security fix alters the `ftplib.FTP`{.interpreted-text role="class"} behavior to not trust the IPv4 address sent from the remote server when setting up a passive data channel. We reuse the ftp server IP address instead. For unusual code requiring the old behavior, set a `trust_server_pasv_ipv4_address` attribute on your FTP instance to `True`. (See `87451`{.interpreted-text role="gh"})
The presence of newline or tab characters in parts of a URL allows for some forms of attacks. Following the WHATWG specification that updates RFC 3986, ASCII newline `\n`, `\r` and tab `\t` characters are stripped from the URL by the parser `urllib.parse`{.interpreted-text role="func"} preventing such attacks. The removal characters are controlled by a new module level variable `urllib.parse._UNSAFE_URL_BYTES_TO_REMOVE`. (See `88048`{.interpreted-text role="gh"})
## Notable security feature in 3.7.14
Converting between `int`{.interpreted-text role="class"} and `str`{.interpreted-text role="class"} in bases other than 2 (binary), 4, 8 (octal), 16 (hexadecimal), or 32 such as base 10 (decimal) now raises a `ValueError`{.interpreted-text role="exc"} 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 `2020-10735`{.interpreted-text role="cve"}. This limit can be configured or disabled by environment variable, command line flag, or `sys`{.interpreted-text role="mod"} APIs. See the `integer string conversion
length limitation <int_max_str_digits>`{.interpreted-text role="ref"} documentation. The default limit is 4300 digits in string form.
|