After a year and a half of development significant release of the programming language . Maintenance updates for the Python 3.8 branch will be released over 18 months. Critical vulnerabilities will be fixed for 5 years until October 2024. Maintenance updates for the 3.8 branch will be released every two months, with the first maintenance release Python 3.8.1 scheduled for December.
Among the added :
- assignment operations within complex expressions. The new operator ":=" allows assignment operations to be performed inside other expressions, for example, to avoid double function calls in conditional statements and when defining loops:
if (n := len(a)) > 10:
…while (block := f.read(256)) != "":
… - new syntax for function argument assignment. When listing arguments during function definition, you can now specify the "/" marker, which separates positional-only parameters from those that allow assignment in any order (using the "variable=value" syntax). Practically, this new feature allows Python functions to fully emulate the behavior of existing functions in C, and to avoid binding to specific names, for example, if a parameter name is planned to be changed in the future.
The "/" flag complements the previously added "*" marker, which separates variables that can only be assigned in the form of "variable=value". For example, in the function "def f(a, b, /, c, d, *, e, f):" the variables "a" and "b" can only be assigned in the order of listing the values,
variables "e" and "f" can only be assigned using "variable=value", while variables "c" and "d" can be assigned in any of the specified ways:f(10, 20, 30, 40, e=50, f=60)
f(10, 20, c=30, d=40, e=50, f=60) - new C API
for configuring Python initialization parameters, allowing complete control over everything and providing enhanced error handling capabilities. The proposed API simplifies the integration of Python interpreter functionality into other applications written in C; - new Vectorcall protocol for faster access to objects written in C. In CPython 3.8, access to Vectorcall is currently limited to internal use, with the transition to publicly available APIs planned for CPython 3.9.
- Runtime Audit Hooks, providing applications and frameworks in Python with access to low-level information about script execution for auditing executed actions (for example, tracking module imports, file openings, trace usage, network socket accesses, and executing code via exec, eval, and run_mod);
- In the module support for Pickle 5 protocol, used for serializing and deserializing objects. Pickle optimizes the transfer of large data volumes between Python processes in multi-core and multi-node configurations, reducing the number of memory copy operations and applying additional optimization techniques, such as utilizing data-specific compression algorithms. The fifth version of the protocol is notable for introducing out-of-band transmission mode, where data can be transferred separately from the main pickle stream.
- The fourth version of the Pickle protocol is enabled by default, which offers higher performance and reduced size of transmitted data compared to the previously suggested default third version;
- In the module several new features have been introduced:
- Class for associative arrays, where type information for the data associated with keys is explicitly defined ("TypedDict('Point2D', x=int, y=int, label=str)").
- Type , allowing a parameter or return value to be restricted to several predefined values ("Literal['connected', 'disconnected']").
- The construct "" allows for defining values of variables, functions, methods, and classes that cannot be changed or reassigned ("pi: Final[float] = 3.1415926536").
- Added the ability to assign a cache for compiled bytecode files, stored in a separate FS tree and separate from code directories. The path for saving bytecode files is specified through the variable or the "-X pycache_prefix" option;
- the ability to create debug builds of Python that use an identical ABI to the release, allowing debug builds to load C extensions compiled for stable releases;
- In f-strings (formatted literals with the prefix 'f'), support for the '=' operator has been added (e.g., "f'{expr=}'"), which allows you to convert an expression to text for easier debugging. For example:
››› user = 'eric_idle'
››› member_since = date(1975, 7, 31)
››› f'{user=} {member_since=}'
"user='eric_idle' member_since=datetime.date(1975, 7, 31)' - The expression "" is allowed to be used within the block ;
- New module added , which allows the use of shared memory segments in multiprocess configurations;
- On the Windows platform, the asyncio implementation has been translated to use the ;
- The performance of the LOAD_GLOBAL instruction has been increased by approximately 40% due to the use of a new object code caching mechanism.
Source: opennet.ru
