bpo-38605: from __future__ import annotations (PEP 563) used to be on this listin previous pre-releases but it has been postponed to Python 3.11 due to some compatibility concerns. You can read the Steering Council communication about it here to learn more.
bpo-44828: A change in the newly released macOS 12 Monterey caused file open and save windows in IDLE and other tkinter applications to be unusable. As of 2021-11-03, the macOS 64-bit universal2 installer file for this release was updated to include a fix in the third-party Tk library for this problem. All other files are unchanged from the original 3.10.0 installer. If you have already installed 3.10.0 from here and encounter this problem on macOS 12 Monterey, download and run the updated installer linked below.
Schwarzschild black holes are also unique because they have a space-like singularity at their core, which means that the singularity doesn't happen at a specific point in space but happens at a specific point in time (the future). This means once you are inside the event horizon you cannot point with your finger towards the direction the singularity is located because the singularity happens in your future: no matter where you move, you will "fall" into it.
Using enclosing parentheses for continuation across multiple linesin context managers is now supported. This allows formatting a longcollection of context managers in multiple lines in a similar wayas it was previously possible with import statements. For instance,all these examples are now valid:
SyntaxError exceptions raised by the interpreter will now highlight thefull error range of the expression that constitutes the syntax error itself,instead of just where the problem is detected. In this way, instead of displaying(before Python 3.10):
PEP 626 brings more precise and reliable line numbers for debugging, profiling and coverage tools.Tracing events, with the correct line number, are generated for all lines of code executed and only for lines of code that are executed.
Structural pattern matching has been added in the form of a match statementand case statements of patterns with associated actions. Patternsconsist of sequences, mappings, primitive data types as well as class instances.Pattern matching enables programs to extract information from complex data types,branch on the structure of data, and apply specific actions based on differentforms of data.
If an exact match is not confirmed, the last case, a wildcard _,if provided, will be used as the matching case. If an exact match isnot confirmed and a wildcard case does not exist, the entire matchblock is a no-op.
Readers may be aware of pattern matching through the simple example of matchinga subject (data object) to a literal (pattern) with the switch statement foundin C, Java or JavaScript (and many other languages). Often the switch statementis used for comparison of an object/expression with case statements containingliterals.
The first pattern has two literals, (0, 0), and may be thought of as anextension of the literal pattern shown above. The next two patterns combine aliteral and a variable, and the variable binds a value from the subject(point). The fourth pattern captures two values, which makes itconceptually similar to the unpacking assignment (x, y) = point.
If you are using classes to structure your data, you can use as a patternthe class name followed by an argument list resembling a constructor. Thispattern has the ability to capture class attributes into variables:
The default encoding of TextIOWrapper and open() isplatform and locale dependent. Since UTF-8 is used on most Unixplatforms, omitting encoding option when opening UTF-8 files(e.g. JSON, YAML, TOML, Markdown) is a very common bug. For example:
PEP 484 introduced the concept of type aliases, only requiring them to betop-level unannotated assignments. This simplicity sometimes made it difficultfor type checkers to distinguish between type aliases and ordinary assignments,especially when forward references or invalid types were involved. Compare:
The views returned by dict.keys(), dict.values() anddict.items() now all have a mapping attribute that gives atypes.MappingProxyType object wrapping the originaldictionary. (Contributed by Dennis Sweeney in bpo-40890.)
Functions have a new __builtins__ attribute which is used to look forbuiltin symbols when a function is executed, instead of looking into__globals__['__builtins__']. The attribute is initialized from__globals__["__builtins__"] if it exists, else from the current builtins.(Contributed by Mark Shannon in bpo-42990.)
Usage of unbound variables, super() and other expressions that mightalter the processing of symbol table as annotations are now renderedeffectless under from __future__ import annotations.(Contributed by Batuhan Taskaya in bpo-42725.)
Hashes of NaN values of both float type anddecimal.Decimal type now depend on object identity. Formerly, theyalways hashed to 0 even though NaN values are not equal to one another.This caused potentially quadratic runtime behavior due to excessive hashcollisions when creating dictionaries and sets containing multiple NaNs.(Contributed by Raymond Hettinger in bpo-43475.)
The __args__ of the parameterized generic forcollections.abc.Callable are now consistent with typing.Callable.collections.abc.Callable generic now flattens type parameters, similarto what typing.Callable currently does. This means thatcollections.abc.Callable[[int, str], str] will have __args__ of(int, str, str); previously this was ([int, str], str). To allow thischange, types.GenericAlias can now be subclassed, and a subclass willbe returned when subscripting the collections.abc.Callable type. Notethat a TypeError may be raised for invalid forms of parameterizingcollections.abc.Callable which may have passed silently in Python 3.9.(Contributed by Ken Jin in bpo-42195.)
Here only birthday is keyword-only. If you set kw_only onindividual fields, be aware that there are rules about re-orderingfields due to keyword-only fields needing to follow non-keyword-onlyfields. See the full dataclasses documentation for details.
The entire distutils package is deprecated, to be removed in Python3.12. Its functionality for specifying package builds has already beencompletely replaced by third-party packages setuptools andpackaging, and most other commonly used APIs are available elsewherein the standard library (such as platform, shutil,subprocess or sysconfig). There are no plans to migrateany other functionality from distutils, and applications that areusing other functions should plan to make private copies of the code.Refer to PEP 632 for discussion.
Rearrange the settings dialog. Split the General tab into Windowsand Shell/Ed tabs. Move help sources, which extend the Help menu, to theExtensions tab. Make space for new options and shorten the dialog. Thelatter makes the dialog better fit small screens. (Contributed by Terry JanReedy in bpo-40468.) Move the indent space setting from the Font tab tothe new Windows tab. (Contributed by Mark Roseman and Terry Jan Reedy inbpo-33962.)
Highlight the new soft keywords match,case, and _ inpattern-matching statements. However, this highlighting is not perfectand will be incorrect in some rare cases, including some _-s incase patterns. (Contributed by Tal Einat in bpo-44010.)
importlib.metadata entry pointsnow provide a nicer experiencefor selecting entry points by group and name through a newimportlib.metadata.EntryPoints class. See the CompatibilityNote in the docs for more info on the deprecation and usage.
Add inspect.get_annotations(), which safely computes the annotationsdefined on an object. It works around the quirks of accessing the annotationson various types of objects, and makes very few assumptions about the objectit examines. inspect.get_annotations() can also correctly un-stringizestringized annotations. inspect.get_annotations() is now consideredbest practice for accessing the annotations dict defined on any Python object;for more information on best practices for working with annotations, please seeAnnotations Best Practices.Relatedly, inspect.signature(),inspect.Signature.from_callable(), and inspect.Signature.from_function()now call inspect.get_annotations() to retrieve annotations. This meansinspect.signature() and inspect.Signature.from_callable() canalso now un-stringize stringized annotations.(Contributed by Larry Hastings in bpo-43817.)
Add os.splice() that allows to move data between two filedescriptors without copying between kernel address space and useraddress space, where one of the file descriptors must refer to apipe. (Contributed by Pablo Galindo in bpo-41625.)
Deprecated function and use of deprecated constants now result ina DeprecationWarning. ssl.SSLContext.options hasOP_NO_SSLv2 and OP_NO_SSLv3 set by default andtherefore cannot warn about setting the flag again. Thedeprecation section has a list of deprecatedfeatures.(Contributed by Christian Heimes in bpo-43880.)
The deprecated protocols SSL 3.0, TLS 1.0, and TLS 1.1 are no longerofficially supported. Python does not block them actively. HoweverOpenSSL build options, distro configurations, vendor patches, and ciphersuites may prevent a successful handshake.
Literal comparisons now respect types. For example,Literal[0] == Literal[False] previously evaluated to True. It isnow False. To support this change, the internally used type cache nowsupports differentiating types.
Literal objects will now raise a TypeError exception duringequality comparisons if any of their parameters are not hashable.Note that declaring Literal with unhashable parameters will not throwan error:
Subclasses of typing.Protocol which only have data variables declaredwill now raise a TypeError when checked with isinstance unless theyare decorated with runtime_checkable(). Previously, these checkspassed silently. Users should decorate theirsubclasses with the runtime_checkable() decoratorif they want runtime protocols.(Contributed by Yurii Karabas in bpo-38908.)
c80f0f1006