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