Text of docs.python.org › uk › 3 › whatsnew › 3.12.html as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Що нового в Python 3.12 — Python 3.15.2 documentation

Навігація індекс модулі | наступний | попередній | Python » 3.15.2 documentation » Що нового в Python » Що нового в Python 3.12 | Theme | Що нового в Python 3.12 ¶ редактор : Адам Тернер (Adam Turner) У цій статті пояснюються нові особливості у Python 3.12 у порівнянні з 3.11. Python 3.12 було випущено 2 жовтня 2023 року.

Для отримання більш детальної інформації дивіться changelog . Дивись також PEP 693 – розклад релізу Python 3.12 Підсумок – основні моменти релізу ¶ Python 3.12 - це стабільний реліз мови програмування Python, що містить зміни в мові та стандартній бібліотеці.

Зміни в бібліотеці зосереджені на очищенні застарілих API, зручності та коректності. Варто зазначити, що зі стандартної бібліотеки було вилучено пакет distutils пакет . Підтримка файлової системи у os та pathlib зазнала низки покращень, а кілька модулів мають кращу продуктивність.

Зміни у мові зосереджені на зручності використання, зокрема, було знято багато обмежень з f-рядок , а підказки «Ви мали на увазі…» продовжують вдосконалюватися. Новий :ref:` синтаксис параметрів типу <whatsnew312-pep695>` та інструкція type покращують ергономічність використання :term:` узагальнених типів <generic type>` та :term:` псевдо для типів <type alias>` для статичної перевірки типів.

Ця стаття не намагається надати повну специфікацію всіх нових особливостей, але натомість надає зручний огляд. Для отримання повної інформації зверніться до документації, наприклад, до Бібліотечної довідки та Мовної довідки . Якщо ви хочете зрозуміти повну реалізацію та обґрунтування змін, зверніться до PEP для конкретної нової особливості; але зауважте, що PEP зазвичай не оновлюються після того, як особливість було повністю впроваджено.

Нові функції синтаксису: PEP 695 , синтаксис параметрів типу та інструкція type Нові особливості граматики: PEP 701 , f-рядки в граматиці Покращення інтерпретатора: PEP 684 , a unique per-interpreter GIL PEP 669 , low impact monitoring Improved „Did you mean …“ suggestions for NameError , ImportError , and SyntaxError exceptions Покращення моделі даних Python: PEP 688 , using the buffer protocol from Python Значні вдосконалення стандартної бібліотеки: The pathlib.Path class now supports subclassing The os module received several improvements for Windows support A command-line interface has been added to the sqlite3 module isinstance() checks against runtime-checkable protocols enjoy a speed up of between two and 20 times The asyncio package has had a number of performance improvements, with some benchmarks showing a 75% speed up.

A command-line interface has been added to the uuid module Due to the changes in PEP 701 , producing tokens via the tokenize module is up to 64% faster. Покращення безпеки: Replace the builtin hashlib implementations of SHA1, SHA3, SHA2-384, SHA2-512, and MD5 with formally verified code from the HACL* project. These builtin implementations remain as fallbacks that are only used when OpenSSL does not provide them.

Покращення C API: PEP 689 , unstable C API tier PEP 683 , immortal objects Покращення реалізації CPython: PEP 709 , comprehension inlining CPython support for the Linux perf profiler Implement stack overflow protection on supported platforms Нові функції набору тексту: PEP 692 , using TypedDict to annotate **kwargs PEP 698 , @typing.override decorator Важливі застарілі, видалення або обмеження: PEP 623 : Remove wstr from Unicode objects in Python’s C API, reducing the size of every str object by at least 8 bytes.

PEP 632 : Remove the distutils package. See the migration guide for advice replacing the APIs it provided. The third-party Setuptools package continues to provide distutils , if you still require it in Python 3.12 and beyond. gh-95299 : Do not pre-install setuptools in virtual environments created with venv . This means that distutils , setuptools , pkg_resources , and easy_install will no longer available by default; to access these run pip install setuptools in the activated virtual environment.

The asynchat , asyncore , and imp modules have been removed, along with several unittest.TestCase method aliases . Нові можливості ¶ PEP 695: Type Parameter Syntax ¶ Generic classes and functions under PEP 484 were declared using a verbose syntax that left the scope of type parameters unclear and required explicit declarations of variance. PEP 695 introduces a new, more compact and explicit way to create generic classes and functions : def max [ T ]( args : Iterable [ T ]) -> T : ... class list [ T ]: def __getitem__ ( self , index : int , / ) -> T : ... def append ( self , element : T ) -> None : ...

In addition, the PEP introduces a new way to declare type aliases using the type statement, which creates an instance of TypeAliasType : type Point = tuple [ float , float ] Type aliases can also be generic : type Point [ T ] = tuple [ T , T ] The new syntax allows declaring TypeVarTuple and ParamSpec parameters, as well as TypeVar parameters with bounds or constraints: type IntFunc [ ** P ] = Callable [ P , int ] # ParamSpec type LabeledTuple [ * Ts ] = tuple [ str , * Ts ] # TypeVarTuple type HashableSequence [ T : Hashable ] = Sequence [ T ] # TypeVar with bound type IntOrStrSequence [ T : ( int , str )] = Sequence [ T ] # TypeVar with constraints The value of type aliases and the bound and constraints of type variables created through this syntax are evaluated only on demand (see lazy evaluation ).

This means type aliases are able to refer to other types defined later in the file. Type parameters declared through a type parameter list are visible within the scope of the declaration and any nested scopes, but not in the outer scope. For example, they can be used in the type annotations for the methods of a generic class or in the class body. However, they cannot be used in the module scope after the class is defined.

See Type parameter lists for a detailed description of the runtime semantics of type parameters. In order to support these scoping semantics, a new kind of scope is introduced, the annotation scope . Annotation scopes behave for the most part like function scopes, but interact differently with enclosing class scopes. In Python 3.13, annotations will also be evaluated in annotation scopes. See PEP 695 for more details. (PEP written by Eric Traut.

Implementation by Jelle Zijlstra, Eric Traut, and others in gh-103764 .) PEP 701: Syntactic formalization of f-strings ¶ PEP 701 lifts some restrictions on the usage of f-strings . Expression components inside f-strin

The rest of this page is on the live site.