Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ade0c3

Browse files
miss-islingtonkoyuki7wStanFromIreland
authored
[3.13]gh-133033: Add docs forTypeIgnore (GH-133034) (#133078)
gh-133033: Add docs for `TypeIgnore` (GH-133034)(cherry picked from commit4e04511)Co-authored-by: Yuki Kobayashi <drsuaimqjgar@gmail.com>Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
1 parent0d53872 commit6ade0c3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎Doc/library/ast.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,43 @@ Pattern matching
17561756

17571757
..versionadded::3.10
17581758

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+
17591796
.. _ast-type-params:
17601797

17611798
Type parameters

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp