Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b33ce4

Browse files
authored
bpo-35766: What's new in the ast and typing modules (#13984)
1 parent 44867bb commit 9b33ce4

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Doc/whatsnew/3.8.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,29 @@ Improved Modules
363363
================
364364

365365

366+
ast
367+
---
368+
369+
AST nodes now have ``end_lineno`` and ``end_col_offset`` attributes,
370+
which give the precise location of the end of the node. (This only
371+
applies to nodes that have ``lineno`` and ``col_offset`` attributes.)
372+
373+
The :func:`ast.parse` function has some new flags:
374+
375+
* ``type_comments=True`` causes it to return the text of :pep:`484` and
376+
:pep:`526` type comments associated with certain AST nodes;
377+
378+
* ``mode='func_type'`` can be used to parse :pep:`484` "signature type
379+
comments" (returned for function definition AST nodes);
380+
381+
* ``feature_version=N`` allows specifying the minor version of an
382+
earlier Python 3 version. (For example, ``feature_version=4`` will
383+
treat ``async`` and ``await`` as non-reserved words.)
384+
385+
New function :func:`ast.get_source_segment` returns the source code
386+
for a specific AST node.
387+
388+
366389
asyncio
367390
-------
368391

@@ -762,6 +785,29 @@ time
762785
Added new clock :data:`~time.CLOCK_UPTIME_RAW` for macOS 10.12.
763786
(Contributed by Joannah Nanjekye in :issue:`35702`.)
764787

788+
789+
typing
790+
------
791+
792+
The :mod:`typing` module incorporates several new features:
793+
794+
* Protocol definitions. See :pep:`544`, :class:`typing.Protocol` and
795+
:func:`typing.runtime_checkable`. Simple ABCs like
796+
:class:`typing.SupportsInt` are now ``Protocol`` subclasses.
797+
798+
* A dictionary type with per-key types. See :pep:`589` and
799+
:class:`typing.TypedDict`.
800+
801+
* Literal types. See :pep:`586` and :class:`typing.Literal`.
802+
803+
* "Final" variables, functions, methods and classes. See :pep:`591`,
804+
:class:`typing.Final` and :func:`typing.final`.
805+
806+
* New protocol class :class:`typing.SupportsIndex`.
807+
808+
* New functions :func:`typing.get_origin` and :func:`typing.get_args`.
809+
810+
765811
unicodedata
766812
-----------
767813

0 commit comments

Comments
 (0)