https://github.com/python/cpython/commit/6ade0c3b2b51b56e68777658d4373d9b80cbdd54
commit: 6ade0c3b2b51b56e68777658d4373d9b80cbdd54
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: sobolevn <m...@sobolevn.me>
date: 2025-04-28T10:55:19Z
summary:

[3.13] gh-133033: Add docs for `TypeIgnore` (GH-133034) (#133078)

gh-133033: Add docs for `TypeIgnore` (GH-133034)
(cherry picked from commit 4e04511cb9c176c32d6f3694f426750d710121cd)

Co-authored-by: Yuki Kobayashi <drsuaimqj...@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+stanfromirel...@users.noreply.github.com>

files:
M Doc/library/ast.rst

diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
index 570ba7989c11cd..55389f53478870 100644
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -1756,6 +1756,43 @@ Pattern matching
 
    .. versionadded:: 3.10
 
+
+Type annotations
+^^^^^^^^^^^^^^^^
+
+.. class:: TypeIgnore(lineno, tag)
+
+   A ``# type: ignore`` comment located at *lineno*.
+   *tag* is the optional tag specified by the form ``# type: ignore <tag>``.
+
+   .. doctest::
+
+      >>> print(ast.dump(ast.parse('x = 1 # type: ignore', 
type_comments=True), indent=4))
+      Module(
+          body=[
+              Assign(
+                  targets=[
+                      Name(id='x', ctx=Store())],
+                  value=Constant(value=1))],
+          type_ignores=[
+              TypeIgnore(lineno=1, tag='')])
+      >>> print(ast.dump(ast.parse('x: bool = 1 # type: ignore[assignment]', 
type_comments=True), indent=4))
+      Module(
+          body=[
+              AnnAssign(
+                  target=Name(id='x', ctx=Store()),
+                  annotation=Name(id='bool', ctx=Load()),
+                  value=Constant(value=1),
+                  simple=1)],
+          type_ignores=[
+              TypeIgnore(lineno=1, tag='[assignment]')])
+
+   .. note::
+      :class:`!TypeIgnore` nodes are not generated when the *type_comments* 
parameter
+      is set to ``False`` (default).  See :func:`ast.parse` for more details.
+
+   .. versionadded:: 3.8
+
 .. _ast-type-params:
 
 Type parameters

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to