Release of the Python 3.8 programming language

After a year and a half of development submitted major programming language release Python 3.8. Corrective updates for Python 3.8 branch is planned release within 18 months. Critical vulnerabilities will be fixed for 5 years until October 2024. Corrective updates for the 3.8 branch will be released every two months, with the first corrective release of Python 3.8.1 scheduled for December.

Among the added innovations:

  • Support assignment operations within complex expressions. With the new “:=” operator, it is possible to perform value assignment operations 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)) != ":
    ...

  • Support new syntax for specifying function arguments. When enumerating arguments during a function definition, you can now specify a "/" to separate arguments that can only be assigned values ​​based on the order in which the values ​​are enumerated during the function call, from arguments that can be assigned in any order (variable=value syntax) ). On the practical side, the new feature allows functions in Python to completely emulate the behavior of existing functions in C, and also to avoid binding to specific names, for example, if the parameter name is planned to be changed in the future.

    The “/” flag complements the previously added “*” flag, separating variables for which only an assignment in the form “variable=value” is applicable. 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 the values ​​are listed,
    variables “e” and “f”, only through the assignment “variable=value”, and variables “c” and “d” in any of the following ways:

    f(10, 20, 30, 40, e=50, f=60)
    f(10, 20, s=30, d=40, e=50, f=60)

  • Added new C API
    to configure Python initialization parameters, allowing complete control over all configuration and providing advanced error handling facilities. The proposed API makes it easy to embed Python interpreter functionality into other C applications;

  • Implemented new Vectorcall protocol for faster access to objects written in C language. In CPython 3.8, access to Vectorcall is still limited to internal use; transfer to the category of publicly accessible APIs is planned in CPython 3.9;
  • Added calls to Runtime Audit Hooks, which provide applications and frameworks in Python with access to low-level information about the progress of the script to audit the actions performed (for example, you can track the import of modules, opening files, using a trace, accessing network sockets, running code through exec, eval and run_mod);
  • In the module pickle provided support for the Pickle 5 protocol, used for serializing and deserializing objects. Pickle allows you to optimize the transfer of large amounts of data between Python processes in multi-core and multi-node configurations by reducing the number of memory copy operations and applying additional optimization techniques such as using data-specific compression algorithms. The fifth version of the protocol is notable for the addition of an out-of-band transmission mode, in which data can be transmitted separately from the main pickle stream.
  • By default, the fourth version of the Pickle protocol is activated, which, compared to the third version previously offered by default, allows for higher performance and a reduction in the size of transmitted data;
  • In the module typing Several new features are introduced:
    • Class TypedDict for associative arrays in which type information is explicitly specified for the data associated with the keys (“TypedDict('Point2D', x=int, y=int, label=str)”).
    • A type Literal, which allows you to limit a parameter or return value to a few predefined values ​​(“Literal['connected', 'disconnected']”).
    • Construction "Final", which makes it possible to define the 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 files with bytecode, saved in a separate FS tree and separated from the directories with the code. The path for saving files with bytecode is set via a variable PYTHONPYCACHEPREFIX or the option "-X pycache_prefix";
  • Implemented the ability to create debug builds of Python that use an ABI identical to the release, which allows you to load extensions written in SI language, compiled for stable releases, in debug builds;
  • f-strings (formatted literals prefixed with 'f') provide support for the = operator (for example, "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)"

  • Expression "keep on going» allowed to be used inside a block finally;
  • Added a new module multiprocessing.shared_memory, allowing the use of shared memory segments in multiprocess configurations;
  • On the Windows platform, the asyncio implementation has been moved to use the class ProactorEventLoop;
  • 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

Add a comment