Skip to content

Commit d208c58

Browse files
author
Yuki Kobayashi
committed
gh-133033: Add document for TypeIgnore
Fixes gh-133033
1 parent 4f18916 commit d208c58

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Doc/library/ast.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,10 +1761,34 @@ Pattern matching
17611761

17621762
.. versionadded:: 3.10
17631763

1764+
Type annotations
1765+
^^^^^^^^^^^^^^^^
1766+
1767+
.. class:: TypeIgnore(lineno, tag)
1768+
1769+
A type ignore comment. ``lineno`` is the location of the ``#type ignore`` comment.
1770+
``tag`` is the optional tag specified by the form ``#type ignore <tag>``.
1771+
1772+
see :func:`ast.parse` for more details.
1773+
1774+
.. doctest::
1775+
1776+
>>> print(ast.dump(ast.parse('x = 1 # type: ignore', type_comments=True), indent=4))
1777+
Module(
1778+
body=[
1779+
Assign(
1780+
targets=[
1781+
Name(id='x', ctx=Store())],
1782+
value=Constant(value=1))],
1783+
type_ignores=[
1784+
TypeIgnore(lineno=1, tag='')])
1785+
1786+
.. versionadded:: 3.8
1787+
17641788
.. _ast-type-params:
17651789

17661790
Type parameters
1767-
^^^^^^^^^^^^^^^
1791+
~~~~~~~~~~~~~~~
17681792

17691793
:ref:`Type parameters <type-params>` can exist on classes, functions, and type
17701794
aliases.

0 commit comments

Comments
 (0)