File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1761,6 +1761,43 @@ Pattern matching
1761
1761
1762
1762
.. versionadded :: 3.10
1763
1763
1764
+
1765
+ Type annotations
1766
+ ^^^^^^^^^^^^^^^^
1767
+
1768
+ .. class :: TypeIgnore(lineno, tag)
1769
+
1770
+ A ``# type: ignore `` comment located at *lineno *.
1771
+ *tag * is the optional tag specified by the form ``# type: ignore <tag> ``.
1772
+
1773
+ .. doctest ::
1774
+
1775
+ >>> print (ast.dump(ast.parse(' x = 1 # type: ignore' , type_comments = True ), indent = 4 ))
1776
+ Module(
1777
+ body=[
1778
+ Assign(
1779
+ targets=[
1780
+ Name(id='x', ctx=Store())],
1781
+ value=Constant(value=1))],
1782
+ type_ignores=[
1783
+ TypeIgnore(lineno=1, tag='')])
1784
+ >>> print (ast.dump(ast.parse(' x: bool = 1 # type: ignore[assignment]' , type_comments = True ), indent = 4 ))
1785
+ Module(
1786
+ body=[
1787
+ AnnAssign(
1788
+ target=Name(id='x', ctx=Store()),
1789
+ annotation=Name(id='bool', ctx=Load()),
1790
+ value=Constant(value=1),
1791
+ simple=1)],
1792
+ type_ignores=[
1793
+ TypeIgnore(lineno=1, tag='[assignment]')])
1794
+
1795
+ .. note ::
1796
+ :class: `!TypeIgnore ` nodes are not generated when the *type_comments * parameter
1797
+ is set to ``False `` (default). See :func: `ast.parse ` for more details.
1798
+
1799
+ .. versionadded :: 3.8
1800
+
1764
1801
.. _ast-type-params :
1765
1802
1766
1803
Type parameters
You can’t perform that action at this time.
0 commit comments