# SOME DESCRIPTIVE TITLE. # Copyright (C) 2001 Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR , YEAR. # # Translators: # python-doc bot, 2025 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-04-13 15:10+0000\n" "PO-Revision-Date: 2025-09-16 00:00+0000\n" "Last-Translator: python-doc bot, 2025\n" "Language-Team: Japanese (https://app.transifex.com/python-doc/teams/5390/" "ja/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: ja\n" "Plural-Forms: nplurals=1; plural=0;\n" #: ../../library/ast.rst:2 msgid ":mod:`!ast` --- Abstract syntax trees" msgstr "" #: ../../library/ast.rst:14 msgid "**Source code:** :source:`Lib/ast.py`" msgstr "**ソースコード:** :source:`Lib/ast.py`" #: ../../library/ast.rst:18 msgid "" "The :mod:`!ast` module helps Python applications to process trees of the " "Python abstract syntax grammar. The abstract syntax itself might change " "with each Python release; this module helps to find out programmatically " "what the current grammar looks like." msgstr "" #: ../../library/ast.rst:23 msgid "" "An abstract syntax tree can be generated by passing :data:`ast." "PyCF_ONLY_AST` as a flag to the :func:`compile` built-in function, or using " "the :func:`parse` helper provided in this module. The result will be a tree " "of objects whose classes all inherit from :class:`ast.AST`. An abstract " "syntax tree can be compiled into a Python code object using the built-in :" "func:`compile` function." msgstr "" "抽象構文木を作成するには、 :data:`ast.PyCF_ONLY_AST` を組み込み関数 :func:" "`compile` のフラグとして渡すか、あるいはこのモジュールで提供されているヘル" "パー関数 :func:`parse` を使います。その結果は、 :class:`ast.AST` を継承したク" "ラスのオブジェクトのツリーとなります。抽象構文木は組み込み関数 :func:" "`compile` を使って Python コード・オブジェクトにコンパイルすることができま" "す。" #: ../../library/ast.rst:33 msgid "Abstract grammar" msgstr "" #: ../../library/ast.rst:35 msgid "The abstract grammar is currently defined as follows:" msgstr "抽象文法は、現在次のように定義されています:" #: ../../library/ast.rst:37 msgid "" "-- ASDL's 4 builtin types are:\n" "-- identifier, int, string, constant\n" "\n" "module Python\n" "{\n" " mod = Module(stmt* body, type_ignore* type_ignores)\n" " | Interactive(stmt* body)\n" " | Expression(expr body)\n" " | FunctionType(expr* argtypes, expr returns)\n" "\n" " stmt = FunctionDef(identifier name, arguments args,\n" " stmt* body, expr* decorator_list, expr? returns,\n" " string? type_comment, type_param* type_params)\n" " | AsyncFunctionDef(identifier name, arguments args,\n" " stmt* body, expr* decorator_list, expr? " "returns,\n" " string? type_comment, type_param* type_params)\n" "\n" " | ClassDef(identifier name,\n" " expr* bases,\n" " keyword* keywords,\n" " stmt* body,\n" " expr* decorator_list,\n" " type_param* type_params)\n" " | Return(expr? value)\n" "\n" " | Delete(expr* targets)\n" " | Assign(expr* targets, expr value, string? type_comment)\n" " | TypeAlias(expr name, type_param* type_params, expr value)\n" " | AugAssign(expr target, operator op, expr value)\n" " -- 'simple' indicates that we annotate simple name without parens\n" " | AnnAssign(expr target, expr annotation, expr? value, int " "simple)\n" "\n" " -- use 'orelse' because else is a keyword in target languages\n" " | For(expr target, expr iter, stmt* body, stmt* orelse, string? " "type_comment)\n" " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, " "string? type_comment)\n" " | While(expr test, stmt* body, stmt* orelse)\n" " | If(expr test, stmt* body, stmt* orelse)\n" " | With(withitem* items, stmt* body, string? type_comment)\n" " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n" "\n" " | Match(expr subject, match_case* cases)\n" "\n" " | Raise(expr? exc, expr? cause)\n" " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* " "finalbody)\n" " | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* " "finalbody)\n" " | Assert(expr test, expr? msg)\n" "\n" " | Import(alias* names)\n" " | ImportFrom(identifier? module, alias* names, int? level)\n" "\n" " | Global(identifier* names)\n" " | Nonlocal(identifier* names)\n" " | Expr(expr value)\n" " | Pass | Break | Continue\n" "\n" " -- col_offset is the byte offset in the utf8 string the parser " "uses\n" " attributes (int lineno, int col_offset, int? end_lineno, int? " "end_col_offset)\n" "\n" " -- BoolOp() can use left & right?\n" " expr = BoolOp(boolop op, expr* values)\n" " | NamedExpr(expr target, expr value)\n" " | BinOp(expr left, operator op, expr right)\n" " | UnaryOp(unaryop op, expr operand)\n" " | Lambda(arguments args, expr body)\n" " | IfExp(expr test, expr body, expr orelse)\n" " | Dict(expr?* keys, expr* values)\n" " | Set(expr* elts)\n" " | ListComp(expr elt, comprehension* generators)\n" " | SetComp(expr elt, comprehension* generators)\n" " | DictComp(expr key, expr value, comprehension* generators)\n" " | GeneratorExp(expr elt, comprehension* generators)\n" " -- the grammar constrains where yield expressions can occur\n" " | Await(expr value)\n" " | Yield(expr? value)\n" " | YieldFrom(expr value)\n" " -- need sequences for compare to distinguish between\n" " -- x < 4 < 3 and (x < 4) < 3\n" " | Compare(expr left, cmpop* ops, expr* comparators)\n" " | Call(expr func, expr* args, keyword* keywords)\n" " | FormattedValue(expr value, int conversion, expr? format_spec)\n" " | Interpolation(expr value, constant str, int conversion, expr? " "format_spec)\n" " | JoinedStr(expr* values)\n" " | TemplateStr(expr* values)\n" " | Constant(constant value, string? kind)\n" "\n" " -- the following expression can appear in assignment context\n" " | Attribute(expr value, identifier attr, expr_context ctx)\n" " | Subscript(expr value, expr slice, expr_context ctx)\n" " | Starred(expr value, expr_context ctx)\n" " | Name(identifier id, expr_context ctx)\n" " | List(expr* elts, expr_context ctx)\n" " | Tuple(expr* elts, expr_context ctx)\n" "\n" " -- can appear only in Subscript\n" " | Slice(expr? lower, expr? upper, expr? step)\n" "\n" " -- col_offset is the byte offset in the utf8 string the parser " "uses\n" " attributes (int lineno, int col_offset, int? end_lineno, int? " "end_col_offset)\n" "\n" " expr_context = Load | Store | Del\n" "\n" " boolop = And | Or\n" "\n" " operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift\n" " | RShift | BitOr | BitXor | BitAnd | FloorDiv\n" "\n" " unaryop = Invert | Not | UAdd | USub\n" "\n" " cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn\n" "\n" " comprehension = (expr target, expr iter, expr* ifs, int is_async)\n" "\n" " excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)\n" " attributes (int lineno, int col_offset, int? end_lineno, " "int? end_col_offset)\n" "\n" " arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs,\n" " expr?* kw_defaults, arg? kwarg, expr* defaults)\n" "\n" " arg = (identifier arg, expr? annotation, string? type_comment)\n" " attributes (int lineno, int col_offset, int? end_lineno, int? " "end_col_offset)\n" "\n" " -- keyword arguments supplied to call (NULL identifier for **kwargs)\n" " keyword = (identifier? arg, expr value)\n" " attributes (int lineno, int col_offset, int? end_lineno, int? " "end_col_offset)\n" "\n" " -- import name with optional 'as' alias.\n" " alias = (identifier name, identifier? asname)\n" " attributes (int lineno, int col_offset, int? end_lineno, int? " "end_col_offset)\n" "\n" " withitem = (expr context_expr, expr? optional_vars)\n" "\n" " match_case = (pattern pattern, expr? guard, stmt* body)\n" "\n" " pattern = MatchValue(expr value)\n" " | MatchSingleton(constant value)\n" " | MatchSequence(pattern* patterns)\n" " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n" " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, " "pattern* kwd_patterns)\n" "\n" " | MatchStar(identifier? name)\n" " -- The optional \"rest\" MatchMapping parameter handles " "capturing extra mapping keys\n" "\n" " | MatchAs(pattern? pattern, identifier? name)\n" " | MatchOr(pattern* patterns)\n" "\n" " attributes (int lineno, int col_offset, int end_lineno, int " "end_col_offset)\n" "\n" " type_ignore = TypeIgnore(int lineno, string tag)\n" "\n" " type_param = TypeVar(identifier name, expr? bound, expr? default_value)\n" " | ParamSpec(identifier name, expr? default_value)\n" " | TypeVarTuple(identifier name, expr? default_value)\n" " attributes (int lineno, int col_offset, int end_lineno, int " "end_col_offset)\n" "}\n" msgstr "" #: ../../library/ast.rst:42 msgid "Node classes" msgstr "Node クラス" #: ../../library/ast.rst:46 msgid "" "This is the base of all AST node classes. The actual node classes are " "derived from the :file:`Parser/Python.asdl` file, which is reproduced :ref:" "`above `. They are defined in the :mod:`!_ast` C module " "and re-exported in :mod:`!ast`." msgstr "" #: ../../library/ast.rst:51 msgid "" "There is one class defined for each left-hand side symbol in the abstract " "grammar (for example, :class:`ast.stmt` or :class:`ast.expr`). In addition, " "there is one class defined for each constructor on the right-hand side; " "these classes inherit from the classes for the left-hand side trees. For " "example, :class:`ast.BinOp` inherits from :class:`ast.expr`. For production " "rules with alternatives (aka \"sums\"), the left-hand side class is " "abstract: only instances of specific constructor nodes are ever created." msgstr "" "抽象文法の左辺のシンボル一つずつにそれぞれ一つのクラスがあります (たとえば :" "class:`ast.stmt` や :class:`ast.expr`)。それに加えて、右辺のコンストラクタ一" "つずつにそれぞれ一つのクラスがあり、これらのクラスは左辺のツリーのクラスを継" "承しています。たとえば、 :class:`ast.BinOp` は :class:`ast.expr` から継承して" "います。代替を伴った生成規則 (production rules with alternatives) (別名 " "\"sums\") の場合、左辺は抽象クラスとなり、特定のコンストラクタ・ノードのイン" "スタンスのみが作成されます。" #: ../../library/ast.rst:64 msgid "" "Each concrete class has an attribute :attr:`!_fields` which gives the names " "of all child nodes." msgstr "" "各具象クラスは属性 :attr:`!_fields` を持っており、すべての子ノードの名前をそ" "こに保持しています。" #: ../../library/ast.rst:67 msgid "" "Each instance of a concrete class has one attribute for each child node, of " "the type as defined in the grammar. For example, :class:`ast.BinOp` " "instances have an attribute :attr:`left` of type :class:`ast.expr`." msgstr "" "具象クラスのインスタンスは、各子ノードに対してそれぞれひとつの属性を持ってい" "ます。この属性は、文法で定義された型となります。たとえば :class:`ast.BinOp` " "のインスタンスは :attr:`left` という属性を持っており、その型は :class:`ast." "expr` です。" #: ../../library/ast.rst:71 msgid "" "If these attributes are marked as optional in the grammar (using a question " "mark), the value might be ``None``. If the attributes can have zero-or-more " "values (marked with an asterisk), the values are represented as Python " "lists. All possible attributes must be present and have valid values when " "compiling an AST with :func:`compile`." msgstr "" "これらの属性が、文法上 (クエスチョンマークを用いて) オプションであるとマーク" "されている場合は、その値が ``None`` となることもあります。属性が0個以上の複数" "の値をとりうる場合 (アスタリスクでマークされている場合) は、値は Python のリ" "ストで表されます。全ての属性は AST を :func:`compile` でコンパイルする際には" "存在しなければならず、そして妥当な値でなければなりません。" #: ../../library/ast.rst:79 msgid "" "The :attr:`!_field_types` attribute on each concrete class is a dictionary " "mapping field names (as also listed in :attr:`_fields`) to their types." msgstr "" #: ../../library/ast.rst:82 msgid "" ">>> ast.TypeVar._field_types\n" "{'name': , 'bound': ast.expr | None, 'default_value': ast.expr " "| None}" msgstr "" #: ../../library/ast.rst:94 msgid "" "Instances of :class:`ast.expr` and :class:`ast.stmt` subclasses have :attr:" "`lineno`, :attr:`col_offset`, :attr:`end_lineno`, and :attr:`end_col_offset` " "attributes. The :attr:`lineno` and :attr:`end_lineno` are the first and " "last line numbers of source text span (1-indexed so the first line is line " "1) and the :attr:`col_offset` and :attr:`end_col_offset` are the " "corresponding UTF-8 byte offsets of the first and last tokens that generated " "the node. The UTF-8 offset is recorded because the parser uses UTF-8 " "internally." msgstr "" ":class:`ast.expr` や :class:`ast.stmt` のサブクラスのインスタンスは :attr:" "`lineno`, :attr:`col_offset`, :attr:`end_lineno`, および :attr:" "`end_col_offset` 属性を持ちます。 :attr:`lineno` と :attr:`end_lineno` はソー" "ステキストの範囲を最初と最後の行番号で表し (1 から数え始めるので、最初の行の" "行番号は 1 となります)、 :attr:`col_offset` と :attr:`end_col_offset` はノー" "ドが生成した最初と最後のトークンの UTF-8 バイトオフセットです。 UTF-8 オフ" "セットはパーサが内部で使用するので記録されます。" #: ../../library/ast.rst:103 msgid "" "Note that the end positions are not required by the compiler and are " "therefore optional. The end offset is *after* the last symbol, for example " "one can get the source segment of a one-line expression node using " "``source_line[node.col_offset : node.end_col_offset]``." msgstr "" "コンパイラは終了位置を必要としないことに注意してください。このため終了位置は" "省略可能です。終了位置を示すオフセットは最後のシンボルの *後の位置* になりま" "す。例えば一行で書かれた式のソースコードのセグメントは ``source_line[node." "col_offset : node.end_col_offset]`` により取得できます。" #: ../../library/ast.rst:108 msgid "" "The constructor of a class :class:`ast.T` parses its arguments as follows:" msgstr "クラス :class:`ast.T` のコンストラクタは引数を次のように解析します:" #: ../../library/ast.rst:110 msgid "" "If there are positional arguments, there must be as many as there are items " "in :attr:`T._fields`; they will be assigned as attributes of these names." msgstr "" "位置引数があるとすれば、 :attr:`T._fields` にあるのと同じだけの個数が無ければ" "なりません。これらの引数はそこにある名前を持った属性として割り当てられます。" #: ../../library/ast.rst:112 msgid "" "If there are keyword arguments, they will set the attributes of the same " "names to the given values." msgstr "" "キーワード引数があるとすれば、それらはその名前の属性にその値を割り当てられま" "す。" #: ../../library/ast.rst:115 msgid "" "For example, to create and populate an :class:`ast.UnaryOp` node, you could " "use ::" msgstr "" "たとえば、 :class:`ast.UnaryOp` ノードを生成して属性を埋めるには、次のように" "することができます ::" #: ../../library/ast.rst:118 msgid "" "node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0),\n" " lineno=0, col_offset=0)" msgstr "" #: ../../library/ast.rst:121 msgid "" "If a field that is optional in the grammar is omitted from the constructor, " "it defaults to ``None``. If a list field is omitted, it defaults to the " "empty list. If a field of type :class:`!ast.expr_context` is omitted, it " "defaults to :class:`Load() `. If any other field is omitted, a :" "exc:`DeprecationWarning` is raised and the AST node will not have this " "field. In Python 3.15, this condition will raise an error." msgstr "" #: ../../library/ast.rst:130 msgid "Class :class:`ast.Constant` is now used for all constants." msgstr ":class:`ast.Constant` が全ての定数に使われるようになりました。" #: ../../library/ast.rst:134 msgid "" "Simple indices are represented by their value, extended slices are " "represented as tuples." msgstr "" "単純なインデックスはその値で表現され、幅を持つスライスはタプルで表現されま" "す。" #: ../../library/ast.rst:139 msgid "" "AST node constructors were changed to provide sensible defaults for omitted " "fields: optional fields now default to ``None``, list fields default to an " "empty list, and fields of type :class:`!ast.expr_context` default to :class:" "`Load() `. Previously, omitted attributes would not exist on " "constructed nodes (accessing them raised :exc:`AttributeError`)." msgstr "" #: ../../library/ast.rst:147 msgid "" "The :meth:`~object.__repr__` output of :class:`~ast.AST` nodes includes the " "values of the node fields." msgstr "" #: ../../library/ast.rst:152 msgid "" "Previous versions of Python provided the AST classes :class:`!ast.Num`, :" "class:`!ast.Str`, :class:`!ast.Bytes`, :class:`!ast.NameConstant` and :class:" "`!ast.Ellipsis`, which were deprecated in Python 3.8. These classes were " "removed in Python 3.14, and their functionality has been replaced with :" "class:`ast.Constant`." msgstr "" #: ../../library/ast.rst:160 msgid "" "Old classes :class:`!ast.Index` and :class:`!ast.ExtSlice` are still " "available, but they will be removed in future Python releases. In the " "meantime, instantiating them will return an instance of a different class." msgstr "" #: ../../library/ast.rst:167 msgid "" "Previous versions of Python allowed the creation of AST nodes that were " "missing required fields. Similarly, AST node constructors allowed arbitrary " "keyword arguments that were set as attributes of the AST node, even if they " "did not match any of the fields of the AST node. This behavior is deprecated " "and will be removed in Python 3.15." msgstr "" #: ../../library/ast.rst:174 msgid "" "The descriptions of the specific node classes displayed here were initially " "adapted from the fantastic `Green Tree Snakes `__ project and all its contributors." msgstr "" "ここに示されている特定のノードクラスについての記述は、素晴らしい `Green Tree " "Snakes `__ プロジェクトと" "そのすべての貢献者の成果物をもとにしています。" #: ../../library/ast.rst:183 msgid "Root nodes" msgstr "" #: ../../library/ast.rst:187 msgid "" "A Python module, as with :ref:`file input `. Node type generated " "by :func:`ast.parse` in the default ``\"exec\"`` *mode*." msgstr "" #: ../../library/ast.rst:190 msgid "``body`` is a :class:`list` of the module's :ref:`ast-statements`." msgstr "" #: ../../library/ast.rst:192 msgid "" "``type_ignores`` is a :class:`list` of the module's type ignore comments; " "see :func:`ast.parse` for more details." msgstr "" #: ../../library/ast.rst:195 msgid "" ">>> print(ast.dump(ast.parse('x = 1'), indent=4))\n" "Module(\n" " body=[\n" " Assign(\n" " targets=[\n" " Name(id='x', ctx=Store())],\n" " value=Constant(value=1))])" msgstr "" #: ../../library/ast.rst:208 msgid "" "A single Python :ref:`expression input `. Node type " "generated by :func:`ast.parse` when *mode* is ``\"eval\"``." msgstr "" #: ../../library/ast.rst:211 msgid "" "``body`` is a single node, one of the :ref:`expression types `." msgstr "" #: ../../library/ast.rst:214 ../../library/ast.rst:284 msgid "" ">>> print(ast.dump(ast.parse('123', mode='eval'), indent=4))\n" "Expression(\n" " body=Constant(value=123))" msgstr "" #: ../../library/ast.rst:223 msgid "" "A single :ref:`interactive input `, like in :ref:`tut-interac`. " "Node type generated by :func:`ast.parse` when *mode* is ``\"single\"``." msgstr "" #: ../../library/ast.rst:226 msgid "``body`` is a :class:`list` of :ref:`statement nodes `." msgstr "" #: ../../library/ast.rst:228 msgid "" ">>> print(ast.dump(ast.parse('x = 1; y = 2', mode='single'), indent=4))\n" "Interactive(\n" " body=[\n" " Assign(\n" " targets=[\n" " Name(id='x', ctx=Store())],\n" " value=Constant(value=1)),\n" " Assign(\n" " targets=[\n" " Name(id='y', ctx=Store())],\n" " value=Constant(value=2))])" msgstr "" #: ../../library/ast.rst:245 msgid "" "A representation of an old-style type comments for functions, as Python " "versions prior to 3.5 didn't support :pep:`484` annotations. Node type " "generated by :func:`ast.parse` when *mode* is ``\"func_type\"``." msgstr "" #: ../../library/ast.rst:249 msgid "Such type comments would look like this::" msgstr "" #: ../../library/ast.rst:251 msgid "" "def sum_two_number(a, b):\n" " # type: (int, int) -> int\n" " return a + b" msgstr "" #: ../../library/ast.rst:255 msgid "" "``argtypes`` is a :class:`list` of :ref:`expression nodes `." msgstr "" #: ../../library/ast.rst:257 msgid "``returns`` is a single :ref:`expression node `." msgstr "" #: ../../library/ast.rst:259 msgid "" ">>> print(ast.dump(ast.parse('(int, str) -> List[int]', mode='func_type'), " "indent=4))\n" "FunctionType(\n" " argtypes=[\n" " Name(id='int', ctx=Load()),\n" " Name(id='str', ctx=Load())],\n" " returns=Subscript(\n" " value=Name(id='List', ctx=Load()),\n" " slice=Name(id='int', ctx=Load()),\n" " ctx=Load()))" msgstr "" #: ../../library/ast.rst:275 msgid "Literals" msgstr "リテラル" #: ../../library/ast.rst:279 msgid "" "A constant value. The ``value`` attribute of the ``Constant`` literal " "contains the Python object it represents. The values represented can be " "instances of :class:`str`, :class:`bytes`, :class:`int`, :class:`float`, :" "class:`complex`, and :class:`bool`, and the constants :data:`None` and :data:" "`Ellipsis`." msgstr "" #: ../../library/ast.rst:293 msgid "" "Node representing a single formatting field in an f-string. If the string " "contains a single formatting field and nothing else the node can be isolated " "otherwise it appears in :class:`JoinedStr`." msgstr "" "このノードは f-string における単一の書式指定置換フィールドを表現します。文字" "列が単一の置換フィールドしか持たず、他に何も含まない場合は、ノードは単独で存" "在できます。そうでない場合は :class:`JoinedStr` の一部としてあらわれます。" #: ../../library/ast.rst:297 msgid "" "``value`` is any expression node (such as a literal, a variable, or a " "function call)." msgstr "" "``value`` は式ツリーのノードのいずれか (リテラル、変数、関数呼び出しなど) で" "す。" #: ../../library/ast.rst:299 ../../library/ast.rst:381 msgid "``conversion`` is an integer:" msgstr "``conversion`` は整数です:" #: ../../library/ast.rst:301 msgid "-1: no formatting" msgstr "-1: 書式指定なし" #: ../../library/ast.rst:302 msgid "97 (``ord('a')``): ``!a`` :func:`ASCII ` formatting" msgstr "" #: ../../library/ast.rst:303 msgid "114 (``ord('r')``): ``!r`` :func:`repr` formatting" msgstr "" #: ../../library/ast.rst:304 msgid "115 (``ord('s')``): ``!s`` :func:`string ` formatting" msgstr "" #: ../../library/ast.rst:306 msgid "" "``format_spec`` is a :class:`JoinedStr` node representing the formatting of " "the value, or ``None`` if no format was specified. Both ``conversion`` and " "``format_spec`` can be set at the same time." msgstr "" "``format_spec`` は値の書式指定を表現する :class:`JoinedStr` ノード、もしくは" "書式指定がない場合は ``None`` です。 ``conversion`` と ``format_spec`` を同時" "に設定することができます。" #: ../../library/ast.rst:313 msgid "" "An f-string, comprising a series of :class:`FormattedValue` and :class:" "`Constant` nodes." msgstr "" ":class:`FormattedValue` ノードと :class:`Constant` ノードの集まりからなる f-" "string です。" #: ../../library/ast.rst:316 msgid "" ">>> print(ast.dump(ast.parse('f\"sin({a}) is {sin(a):.3}\"', mode='eval'), " "indent=4))\n" "Expression(\n" " body=JoinedStr(\n" " values=[\n" " Constant(value='sin('),\n" " FormattedValue(\n" " value=Name(id='a', ctx=Load()),\n" " conversion=-1),\n" " Constant(value=') is '),\n" " FormattedValue(\n" " value=Call(\n" " func=Name(id='sin', ctx=Load()),\n" " args=[\n" " Name(id='a', ctx=Load())]),\n" " conversion=-1,\n" " format_spec=JoinedStr(\n" " values=[\n" " Constant(value='.3')]))]))" msgstr "" #: ../../library/ast.rst:342 msgid "" "Node representing a template string literal, comprising a series of :class:" "`Interpolation` and :class:`Constant` nodes. These nodes may be any order, " "and do not need to be interleaved." msgstr "" #: ../../library/ast.rst:346 msgid "" ">>> expr = ast.parse('t\"{name} finished {place:ordinal}\"', mode='eval')\n" ">>> print(ast.dump(expr, indent=4))\n" "Expression(\n" " body=TemplateStr(\n" " values=[\n" " Interpolation(\n" " value=Name(id='name', ctx=Load()),\n" " str='name',\n" " conversion=-1),\n" " Constant(value=' finished '),\n" " Interpolation(\n" " value=Name(id='place', ctx=Load()),\n" " str='place',\n" " conversion=-1,\n" " format_spec=JoinedStr(\n" " values=[\n" " Constant(value='ordinal')]))]))" msgstr "" #: ../../library/ast.rst:370 msgid "" "Node representing a single interpolation field in a template string literal." msgstr "" #: ../../library/ast.rst:372 msgid "" "``value`` is any expression node (such as a literal, a variable, or a " "function call). This has the same meaning as ``FormattedValue.value``." msgstr "" #: ../../library/ast.rst:375 msgid "" "``str`` is a constant containing the text of the interpolation expression." msgstr "" #: ../../library/ast.rst:377 msgid "" "If ``str`` is set to ``None``, then ``value`` is used to generate code when " "calling :func:`ast.unparse`. This no longer guarantees that the generated " "code is identical to the original and is intended for code generation." msgstr "" #: ../../library/ast.rst:383 msgid "-1: no conversion" msgstr "" #: ../../library/ast.rst:384 msgid "97 (``ord('a')``): ``!a`` :func:`ASCII ` conversion" msgstr "" #: ../../library/ast.rst:385 msgid "114 (``ord('r')``): ``!r`` :func:`repr` conversion" msgstr "" #: ../../library/ast.rst:386 msgid "115 (``ord('s')``): ``!s`` :func:`string ` conversion" msgstr "" #: ../../library/ast.rst:388 msgid "This has the same meaning as ``FormattedValue.conversion``." msgstr "" #: ../../library/ast.rst:389 msgid "" "``format_spec`` is a :class:`JoinedStr` node representing the formatting of " "the value, or ``None`` if no format was specified. Both ``conversion`` and " "``format_spec`` can be set at the same time. This has the same meaning as " "``FormattedValue.format_spec``." msgstr "" #: ../../library/ast.rst:398 msgid "" "A list or tuple. ``elts`` holds a list of nodes representing the elements. " "``ctx`` is :class:`Store` if the container is an assignment target (i.e. " "``(x,y)=something``), and :class:`Load` otherwise." msgstr "" "リストまたはタプルをあらわします。 ``elts`` は内包する要素を表現するノードの" "リストを保持します。 ``ctx`` はコンテナが代入のターゲットである場合 (たとえ" "ば ``(x,y)=something`` のような場合) は :class:`Store` であり、そうでない場合" "は :class:`Load` です。" #: ../../library/ast.rst:402 msgid "" ">>> print(ast.dump(ast.parse('[1, 2, 3]', mode='eval'), indent=4))\n" "Expression(\n" " body=List(\n" " elts=[\n" " Constant(value=1),\n" " Constant(value=2),\n" " Constant(value=3)],\n" " ctx=Load()))\n" ">>> print(ast.dump(ast.parse('(1, 2, 3)', mode='eval'), indent=4))\n" "Expression(\n" " body=Tuple(\n" " elts=[\n" " Constant(value=1),\n" " Constant(value=2),\n" " Constant(value=3)],\n" " ctx=Load()))" msgstr "" #: ../../library/ast.rst:424 msgid "A set. ``elts`` holds a list of nodes representing the set's elements." msgstr "" "集合 (set) をあらわします。 ``elts`` は集合の各要素を表現するノードのリストを" "保持します。" #: ../../library/ast.rst:426 msgid "" ">>> print(ast.dump(ast.parse('{1, 2, 3}', mode='eval'), indent=4))\n" "Expression(\n" " body=Set(\n" " elts=[\n" " Constant(value=1),\n" " Constant(value=2),\n" " Constant(value=3)]))" msgstr "" #: ../../library/ast.rst:439 msgid "" "A dictionary. ``keys`` and ``values`` hold lists of nodes representing the " "keys and the values respectively, in matching order (what would be returned " "when calling :code:`dictionary.keys()` and :code:`dictionary.values()`)." msgstr "" "辞書をあらわします。 ``keys`` と ``values`` はそれぞれキーと値のノードのリス" "ト を順序が一致した形で (それぞれ :code:`dictionary.keys()` と :code:" "`dictionary.values()` を呼び出したときに返される順序で) 保持します。" #: ../../library/ast.rst:443 msgid "" "When doing dictionary unpacking using dictionary literals the expression to " "be expanded goes in the ``values`` list, with a ``None`` at the " "corresponding position in ``keys``." msgstr "" "辞書リテラルを使って辞書を展開した場合、展開された式ツリーにおいて辞書は " "``values`` リストに入り、 ``keys`` の対応する位置には ``None`` が入ります。" #: ../../library/ast.rst:447 msgid "" ">>> print(ast.dump(ast.parse('{\"a\":1, **d}', mode='eval'), indent=4))\n" "Expression(\n" " body=Dict(\n" " keys=[\n" " Constant(value='a'),\n" " None],\n" " values=[\n" " Constant(value=1),\n" " Name(id='d', ctx=Load())]))" msgstr "" #: ../../library/ast.rst:461 msgid "Variables" msgstr "変数" #: ../../library/ast.rst:465 msgid "" "A variable name. ``id`` holds the name as a string, and ``ctx`` is one of " "the following types." msgstr "" "変数名をあらわします。 ``id`` は変数名を文字列で保持し、 ``ctx`` は以下に示す" "型のいずれかです。" #: ../../library/ast.rst:473 msgid "" "Variable references can be used to load the value of a variable, to assign a " "new value to it, or to delete it. Variable references are given a context to " "distinguish these cases." msgstr "" "変数の参照は変数の値をロードするか、新しい値を割り当てるか、または値を削除す" "るために使うことができます。変数の参照はこれら3つの場合を区別するためのコンテ" "キストによって与えられます。" #: ../../library/ast.rst:477 msgid "" ">>> print(ast.dump(ast.parse('a'), indent=4))\n" "Module(\n" " body=[\n" " Expr(\n" " value=Name(id='a', ctx=Load()))])\n" "\n" ">>> print(ast.dump(ast.parse('a = 1'), indent=4))\n" "Module(\n" " body=[\n" " Assign(\n" " targets=[\n" " Name(id='a', ctx=Store())],\n" " value=Constant(value=1))])\n" "\n" ">>> print(ast.dump(ast.parse('del a'), indent=4))\n" "Module(\n" " body=[\n" " Delete(\n" " targets=[\n" " Name(id='a', ctx=Del())])])" msgstr "" #: ../../library/ast.rst:503 msgid "" "A ``*var`` variable reference. ``value`` holds the variable, typically a :" "class:`Name` node. This type must be used when building a :class:`Call` node " "with ``*args``." msgstr "" "``*var`` 形式の変数の参照をあらわします。 ``value`` は変数、典型的には :" "class:`Name` ノード、を保持します。この型は ``*args`` を伴う関数呼び出しノー" "ド :class:`Call` を構築する際に使用します。 " #: ../../library/ast.rst:507 msgid "" ">>> print(ast.dump(ast.parse('a, *b = it'), indent=4))\n" "Module(\n" " body=[\n" " Assign(\n" " targets=[\n" " Tuple(\n" " elts=[\n" " Name(id='a', ctx=Store()),\n" " Starred(\n" " value=Name(id='b', ctx=Store()),\n" " ctx=Store())],\n" " ctx=Store())],\n" " value=Name(id='it', ctx=Load()))])" msgstr "" #: ../../library/ast.rst:527 msgid "Expressions" msgstr "式 (expression)" #: ../../library/ast.rst:531 msgid "" "When an expression, such as a function call, appears as a statement by " "itself with its return value not used or stored, it is wrapped in this " "container. ``value`` holds one of the other nodes in this section, a :class:" "`Constant`, a :class:`Name`, a :class:`Lambda`, a :class:`Yield` or :class:" "`YieldFrom` node." msgstr "" "関数呼び出しのような式がそれ自身で文となり、戻り値が使われないかまたは保存さ" "れないとき、その式はこのコンテナでラップされます。 ``value`` はこの節で説明す" "る他のノード、 :class:`Constant` ノード、 :class:`Name` ノード、 :class:" "`Lambda` ノード :class:`Yield` ノードまたは :class:`YieldFrom` ノードのいずれ" "かを保持します。" #: ../../library/ast.rst:536 msgid "" ">>> print(ast.dump(ast.parse('-a'), indent=4))\n" "Module(\n" " body=[\n" " Expr(\n" " value=UnaryOp(\n" " op=USub(),\n" " operand=Name(id='a', ctx=Load())))])" msgstr "" #: ../../library/ast.rst:549 msgid "" "A unary operation. ``op`` is the operator, and ``operand`` any expression " "node." msgstr "" "単項演算をあらわします。 ``op`` は演算子で、 ``operand`` は任意の式ツリーの" "ノードです。" #: ../../library/ast.rst:558 msgid "" "Unary operator tokens. :class:`Not` is the ``not`` keyword, :class:`Invert` " "is the ``~`` operator." msgstr "" "単項演算の演算子をあらわします。 :class:`Not` は論理否定キーワード ``not`` で" "あり、 :class:`Invert` はビット反転演算子 ``~`` です。" #: ../../library/ast.rst:561 msgid "" ">>> print(ast.dump(ast.parse('not x', mode='eval'), indent=4))\n" "Expression(\n" " body=UnaryOp(\n" " op=Not(),\n" " operand=Name(id='x', ctx=Load())))" msgstr "" #: ../../library/ast.rst:572 msgid "" "A binary operation (like addition or division). ``op`` is the operator, and " "``left`` and ``right`` are any expression nodes." msgstr "" "(加算や減算のような) 二項演算をあらわします。 ``op`` は演算子、 ``left`` と " "``right`` は任意の式ツリーのノードです。" #: ../../library/ast.rst:575 msgid "" ">>> print(ast.dump(ast.parse('x + y', mode='eval'), indent=4))\n" "Expression(\n" " body=BinOp(\n" " left=Name(id='x', ctx=Load()),\n" " op=Add(),\n" " right=Name(id='y', ctx=Load())))" msgstr "" #: ../../library/ast.rst:599 msgid "Binary operator tokens." msgstr "二項演算の演算子をあらわします。" #: ../../library/ast.rst:604 msgid "" "A boolean operation, 'or' or 'and'. ``op`` is :class:`Or` or :class:`And`. " "``values`` are the values involved. Consecutive operations with the same " "operator, such as ``a or b or c``, are collapsed into one node with several " "values." msgstr "" "'or' や 'and' のような論理演算をあらわします。 ``op`` は :class:`Or` または :" "class:`And` です。 ``values`` は必要な値のリストです。 ``a or b or c`` のよう" "に同じ演算子を使う連続した演算は、複数の値を持った単一のノードとして表現され" "ます。" #: ../../library/ast.rst:609 msgid "This doesn't include ``not``, which is a :class:`UnaryOp`." msgstr "``not`` は単項演算 :class:`UnaryOp` のため、ここには含まれません。" #: ../../library/ast.rst:611 msgid "" ">>> print(ast.dump(ast.parse('x or y', mode='eval'), indent=4))\n" "Expression(\n" " body=BoolOp(\n" " op=Or(),\n" " values=[\n" " Name(id='x', ctx=Load()),\n" " Name(id='y', ctx=Load())]))" msgstr "" #: ../../library/ast.rst:625 msgid "Boolean operator tokens." msgstr "論理演算の演算子をあらわします。" #: ../../library/ast.rst:630 msgid "" "A comparison of two or more values. ``left`` is the first value in the " "comparison, ``ops`` the list of operators, and ``comparators`` the list of " "values after the first element in the comparison." msgstr "" "2つ以上の値の比較をあらわします。 ``left`` 比較の中の最初の値、``ops`` は演算" "子のリスト、 ``comparators`` は2つ目以降の値のリストです。" #: ../../library/ast.rst:634 msgid "" ">>> print(ast.dump(ast.parse('1 <= a < 10', mode='eval'), indent=4))\n" "Expression(\n" " body=Compare(\n" " left=Constant(value=1),\n" " ops=[\n" " LtE(),\n" " Lt()],\n" " comparators=[\n" " Name(id='a', ctx=Load()),\n" " Constant(value=10)]))" msgstr "" #: ../../library/ast.rst:659 msgid "Comparison operator tokens." msgstr "比較演算の演算子をあらわします。" #: ../../library/ast.rst:664 msgid "" "A function call. ``func`` is the function, which will often be a :class:" "`Name` or :class:`Attribute` object. Of the arguments:" msgstr "" "関数呼び出しをあらわします。 ``func`` は関数で、多くの場合 :class:`Name` また" "は :class:`Attribute` のオブジェクトです。 関数呼び出しの引数:" #: ../../library/ast.rst:667 msgid "``args`` holds a list of the arguments passed by position." msgstr "``args`` は位置引数のリストを保持します。 " #: ../../library/ast.rst:668 msgid "" "``keywords`` holds a list of :class:`.keyword` objects representing " "arguments passed by keyword." msgstr "" #: ../../library/ast.rst:671 msgid "" "The ``args`` and ``keywords`` arguments are optional and default to empty " "lists." msgstr "" #: ../../library/ast.rst:673 msgid "" ">>> print(ast.dump(ast.parse('func(a, b=c, *d, **e)', mode='eval'), " "indent=4))\n" "Expression(\n" " body=Call(\n" " func=Name(id='func', ctx=Load()),\n" " args=[\n" " Name(id='a', ctx=Load()),\n" " Starred(\n" " value=Name(id='d', ctx=Load()),\n" " ctx=Load())],\n" " keywords=[\n" " keyword(\n" " arg='b',\n" " value=Name(id='c', ctx=Load())),\n" " keyword(\n" " value=Name(id='e', ctx=Load()))]))" msgstr "" #: ../../library/ast.rst:694 msgid "" "A keyword argument to a function call or class definition. ``arg`` is a raw " "string of the parameter name, ``value`` is a node to pass in." msgstr "" "関数呼び出しまたはクラス定義のキーワード引数をあらわします。 ``arg`` はパラ" "メータ名をあらわす文字列、 ``value`` は引数に渡す値をあらわすノードです。" #: ../../library/ast.rst:700 msgid "" "An expression such as ``a if b else c``. Each field holds a single node, so " "in the following example, all three are :class:`Name` nodes." msgstr "" "``a if b else c`` のような式をあらわします。各フィールドは単一のノードを保持" "します。以下の例では、3つの式ノードはすべて :class:`Name` ノードです。" #: ../../library/ast.rst:703 msgid "" ">>> print(ast.dump(ast.parse('a if b else c', mode='eval'), indent=4))\n" "Expression(\n" " body=IfExp(\n" " test=Name(id='b', ctx=Load()),\n" " body=Name(id='a', ctx=Load()),\n" " orelse=Name(id='c', ctx=Load())))" msgstr "" #: ../../library/ast.rst:715 msgid "" "Attribute access, e.g. ``d.keys``. ``value`` is a node, typically a :class:" "`Name`. ``attr`` is a bare string giving the name of the attribute, and " "``ctx`` is :class:`Load`, :class:`Store` or :class:`Del` according to how " "the attribute is acted on." msgstr "" "たとえば ``d.keys`` のような属性へのアクセスです。 ``value`` はノードで、典型" "的には :class:`Name` です。 ``attr`` は属性名を与える生の文字列で、 ``ctx`` " "はその属性がどのように振る舞うかに応じて :class:`Load`、 :class:`Store` また" "は :class:`Del` のいずれかです。" #: ../../library/ast.rst:720 msgid "" ">>> print(ast.dump(ast.parse('snake.colour', mode='eval'), indent=4))\n" "Expression(\n" " body=Attribute(\n" " value=Name(id='snake', ctx=Load()),\n" " attr='colour',\n" " ctx=Load()))" msgstr "" #: ../../library/ast.rst:732 msgid "" "A named expression. This AST node is produced by the assignment expressions " "operator (also known as the walrus operator). As opposed to the :class:" "`Assign` node in which the first argument can be multiple nodes, in this " "case both ``target`` and ``value`` must be single nodes." msgstr "" "代入式です。この AST ノードは代入式演算子(ウォルラス演算子、または「セイウチ" "演算子」としても知られています)によって生成されます。第一引数が複数のノード" "であってもよい :class:`Assign` ノードと異なり、このノードの場合は ``target`` " "と ``value`` の両方が単一のノードでなければなりません。" #: ../../library/ast.rst:737 msgid "" ">>> print(ast.dump(ast.parse('(x := 4)', mode='eval'), indent=4))\n" "Expression(\n" " body=NamedExpr(\n" " target=Name(id='x', ctx=Store()),\n" " value=Constant(value=4)))" msgstr "" #: ../../library/ast.rst:748 msgid "Subscripting" msgstr "配列要素の参照 (Subscripting)" #: ../../library/ast.rst:752 msgid "" "A subscript, such as ``l[1]``. ``value`` is the subscripted object (usually " "sequence or mapping). ``slice`` is an index, slice or key. It can be a :" "class:`Tuple` and contain a :class:`Slice`. ``ctx`` is :class:`Load`, :class:" "`Store` or :class:`Del` according to the action performed with the subscript." msgstr "" "``l[1]`` のような配列要素の参照をあらわします。 ``value`` は参照元のオブジェ" "クトです (通常シーケンス型またはマッピング型)。 ``slice`` はインデックス、ス" "ライス、またはキーです。 :class:`Slice` を含む :class:`Tuple` でもかまいませ" "ん。 ``ctx`` は要素の参照により実行されるアクションに応じて :class:`Load`、 :" "class:`Store` または :class:`Del` のいずれかです。" #: ../../library/ast.rst:758 msgid "" ">>> print(ast.dump(ast.parse('l[1:2, 3]', mode='eval'), indent=4))\n" "Expression(\n" " body=Subscript(\n" " value=Name(id='l', ctx=Load()),\n" " slice=Tuple(\n" " elts=[\n" " Slice(\n" " lower=Constant(value=1),\n" " upper=Constant(value=2)),\n" " Constant(value=3)],\n" " ctx=Load()),\n" " ctx=Load()))" msgstr "" #: ../../library/ast.rst:776 msgid "" "Regular slicing (on the form ``lower:upper`` or ``lower:upper:step``). Can " "occur only inside the *slice* field of :class:`Subscript`, either directly " "or as an element of :class:`Tuple`." msgstr "" "基本的なスライス操作 (``lower:upper`` や ``lower:upper:step`` の形式) をあら" "わします。 :class:`Subscript` の *slice* フィールドでの直接指定か、または :" "class:`Tuple` の要素として指定する場合のみ利用可能です。" #: ../../library/ast.rst:780 msgid "" ">>> print(ast.dump(ast.parse('l[1:2]', mode='eval'), indent=4))\n" "Expression(\n" " body=Subscript(\n" " value=Name(id='l', ctx=Load()),\n" " slice=Slice(\n" " lower=Constant(value=1),\n" " upper=Constant(value=2)),\n" " ctx=Load()))" msgstr "" #: ../../library/ast.rst:793 msgid "Comprehensions" msgstr "内包表記 (Comprehension)" #: ../../library/ast.rst:800 msgid "" "List and set comprehensions, generator expressions, and dictionary " "comprehensions. ``elt`` (or ``key`` and ``value``) is a single node " "representing the part that will be evaluated for each item." msgstr "" "リストや集合の内包表記、ジェネレータ、および辞書の内包表記です。 ``elt`` (ま" "たは ``key`` と ``value``) は各要素として評価される部品をあらわす単一のノード" "です。" #: ../../library/ast.rst:804 msgid "``generators`` is a list of :class:`comprehension` nodes." msgstr "``generators`` は :class:`comprehension` ノードのリストです。" #: ../../library/ast.rst:806 msgid "" ">>> print(ast.dump(\n" "... ast.parse('[x for x in numbers]', mode='eval'),\n" "... indent=4,\n" "... ))\n" "Expression(\n" " body=ListComp(\n" " elt=Name(id='x', ctx=Load()),\n" " generators=[\n" " comprehension(\n" " target=Name(id='x', ctx=Store()),\n" " iter=Name(id='numbers', ctx=Load()),\n" " is_async=0)]))\n" ">>> print(ast.dump(\n" "... ast.parse('{x: x**2 for x in numbers}', mode='eval'),\n" "... indent=4,\n" "... ))\n" "Expression(\n" " body=DictComp(\n" " key=Name(id='x', ctx=Load()),\n" " value=BinOp(\n" " left=Name(id='x', ctx=Load()),\n" " op=Pow(),\n" " right=Constant(value=2)),\n" " generators=[\n" " comprehension(\n" " target=Name(id='x', ctx=Store()),\n" " iter=Name(id='numbers', ctx=Load()),\n" " is_async=0)]))\n" ">>> print(ast.dump(\n" "... ast.parse('{x for x in numbers}', mode='eval'),\n" "... indent=4,\n" "... ))\n" "Expression(\n" " body=SetComp(\n" " elt=Name(id='x', ctx=Load()),\n" " generators=[\n" " comprehension(\n" " target=Name(id='x', ctx=Store()),\n" " iter=Name(id='numbers', ctx=Load()),\n" " is_async=0)]))" msgstr "" #: ../../library/ast.rst:852 msgid "" "One ``for`` clause in a comprehension. ``target`` is the reference to use " "for each element - typically a :class:`Name` or :class:`Tuple` node. " "``iter`` is the object to iterate over. ``ifs`` is a list of test " "expressions: each ``for`` clause can have multiple ``ifs``." msgstr "" "内包表記におけるひとつの ``for`` 節をあらわします。 ``target`` は各要素への参" "照です - 典型的には :class:`Name` または :class:`Tuple` ノードです。 " "``iter`` はイテレートする対象のオブジェクトです。 ``ifs`` は条件節のリストで" "す: 各 ``for`` 節は複数の ``ifs`` を持つことができます。" #: ../../library/ast.rst:857 msgid "" "``is_async`` indicates a comprehension is asynchronous (using an ``async " "for`` instead of ``for``). The value is an integer (0 or 1)." msgstr "" "``is_async`` は内包表記が非同期であることを示します (``async for`` を " "``for`` の代わりに使います)。値は整数です (0 または 1)。" #: ../../library/ast.rst:860 msgid "" ">>> print(ast.dump(ast.parse('[ord(c) for line in file for c in line]', " "mode='eval'),\n" "... indent=4)) # Multiple comprehensions in one.\n" "Expression(\n" " body=ListComp(\n" " elt=Call(\n" " func=Name(id='ord', ctx=Load()),\n" " args=[\n" " Name(id='c', ctx=Load())]),\n" " generators=[\n" " comprehension(\n" " target=Name(id='line', ctx=Store()),\n" " iter=Name(id='file', ctx=Load()),\n" " is_async=0),\n" " comprehension(\n" " target=Name(id='c', ctx=Store()),\n" " iter=Name(id='line', ctx=Load()),\n" " is_async=0)]))\n" "\n" ">>> print(ast.dump(ast.parse('(n**2 for n in it if n>5 if n<10)', " "mode='eval'),\n" "... indent=4)) # generator comprehension\n" "Expression(\n" " body=GeneratorExp(\n" " elt=BinOp(\n" " left=Name(id='n', ctx=Load()),\n" " op=Pow(),\n" " right=Constant(value=2)),\n" " generators=[\n" " comprehension(\n" " target=Name(id='n', ctx=Store()),\n" " iter=Name(id='it', ctx=Load()),\n" " ifs=[\n" " Compare(\n" " left=Name(id='n', ctx=Load()),\n" " ops=[\n" " Gt()],\n" " comparators=[\n" " Constant(value=5)]),\n" " Compare(\n" " left=Name(id='n', ctx=Load()),\n" " ops=[\n" " Lt()],\n" " comparators=[\n" " Constant(value=10)])],\n" " is_async=0)]))\n" "\n" ">>> print(ast.dump(ast.parse('[i async for i in soc]', mode='eval'),\n" "... indent=4)) # Async comprehension\n" "Expression(\n" " body=ListComp(\n" " elt=Name(id='i', ctx=Load()),\n" " generators=[\n" " comprehension(\n" " target=Name(id='i', ctx=Store()),\n" " iter=Name(id='soc', ctx=Load()),\n" " is_async=1)]))" msgstr "" #: ../../library/ast.rst:922 msgid "Statements" msgstr "文 (Statements)" #: ../../library/ast.rst:926 msgid "" "An assignment. ``targets`` is a list of nodes, and ``value`` is a single " "node." msgstr "" "代入です。 ``targets`` はノードのリスト、 ``value`` は単一のノードです。" #: ../../library/ast.rst:928 msgid "" "Multiple nodes in ``targets`` represents assigning the same value to each. " "Unpacking is represented by putting a :class:`Tuple` or :class:`List` within " "``targets``." msgstr "" "``targets`` の複数のノードは、それぞれに対して同じ値を代入することをあらわし" "ます。分割代入は ``targets`` 内に :class:`Tuple` または :class:`List` を置く" "ことで表現されます。" #: ../../library/ast.rst:934 ../../library/ast.rst:1229 #: ../../library/ast.rst:1423 ../../library/ast.rst:1989 msgid "" "``type_comment`` is an optional string with the type annotation as a comment." msgstr "" "``type_comment`` はコメントとして型アノテーションをあらわすオプション文字列で" "す。" #: ../../library/ast.rst:936 msgid "" ">>> print(ast.dump(ast.parse('a = b = 1'), indent=4)) # Multiple assignment\n" "Module(\n" " body=[\n" " Assign(\n" " targets=[\n" " Name(id='a', ctx=Store()),\n" " Name(id='b', ctx=Store())],\n" " value=Constant(value=1))])\n" "\n" ">>> print(ast.dump(ast.parse('a,b = c'), indent=4)) # Unpacking\n" "Module(\n" " body=[\n" " Assign(\n" " targets=[\n" " Tuple(\n" " elts=[\n" " Name(id='a', ctx=Store()),\n" " Name(id='b', ctx=Store())],\n" " ctx=Store())],\n" " value=Name(id='c', ctx=Load()))])" msgstr "" #: ../../library/ast.rst:962 msgid "" "An assignment with a type annotation. ``target`` is a single node and can be " "a :class:`Name`, an :class:`Attribute` or a :class:`Subscript`. " "``annotation`` is the annotation, such as a :class:`Constant` or :class:" "`Name` node. ``value`` is a single optional node." msgstr "" #: ../../library/ast.rst:967 msgid "" "``simple`` is always either 0 (indicating a \"complex\" target) or 1 " "(indicating a \"simple\" target). A \"simple\" target consists solely of a :" "class:`Name` node that does not appear between parentheses; all other " "targets are considered complex. Only simple targets appear in the :attr:" "`~object.__annotations__` dictionary of modules and classes." msgstr "" #: ../../library/ast.rst:973 msgid "" ">>> print(ast.dump(ast.parse('c: int'), indent=4))\n" "Module(\n" " body=[\n" " AnnAssign(\n" " target=Name(id='c', ctx=Store()),\n" " annotation=Name(id='int', ctx=Load()),\n" " simple=1)])\n" "\n" ">>> print(ast.dump(ast.parse('(a): int = 1'), indent=4)) # Annotation with " "parenthesis\n" "Module(\n" " body=[\n" " AnnAssign(\n" " target=Name(id='a', ctx=Store()),\n" " annotation=Name(id='int', ctx=Load()),\n" " value=Constant(value=1),\n" " simple=0)])\n" "\n" ">>> print(ast.dump(ast.parse('a.b: int'), indent=4)) # Attribute annotation\n" "Module(\n" " body=[\n" " AnnAssign(\n" " target=Attribute(\n" " value=Name(id='a', ctx=Load()),\n" " attr='b',\n" " ctx=Store()),\n" " annotation=Name(id='int', ctx=Load()),\n" " simple=0)])\n" "\n" ">>> print(ast.dump(ast.parse('a[1]: int'), indent=4)) # Subscript " "annotation\n" "Module(\n" " body=[\n" " AnnAssign(\n" " target=Subscript(\n" " value=Name(id='a', ctx=Load()),\n" " slice=Constant(value=1),\n" " ctx=Store()),\n" " annotation=Name(id='int', ctx=Load()),\n" " simple=0)])" msgstr "" #: ../../library/ast.rst:1017 msgid "" "Augmented assignment, such as ``a += 1``. In the following example, " "``target`` is a :class:`Name` node for ``x`` (with the :class:`Store` " "context), ``op`` is :class:`Add`, and ``value`` is a :class:`Constant` with " "value for 1." msgstr "" "``a += 1`` のような累積代入をあらわします。下記の例では、 ``target`` は (:" "class:`Store` コンテキストを伴う) ``x`` のための :class:`Name` ノード、 " "``op`` は :class:`Add` 演算子、そして ``value`` は定数1をあらわす :class:" "`Constant` ノードです。" #: ../../library/ast.rst:1022 msgid "" "The ``target`` attribute cannot be of class :class:`Tuple` or :class:`List`, " "unlike the targets of :class:`Assign`." msgstr "" ":class:`Assign` と異なり、 ``target`` 属性は class :class:`Tuple` や :class:" "`List` であってはいけません。" #: ../../library/ast.rst:1025 msgid "" ">>> print(ast.dump(ast.parse('x += 2'), indent=4))\n" "Module(\n" " body=[\n" " AugAssign(\n" " target=Name(id='x', ctx=Store()),\n" " op=Add(),\n" " value=Constant(value=2))])" msgstr "" #: ../../library/ast.rst:1038 msgid "" "A ``raise`` statement. ``exc`` is the exception object to be raised, " "normally a :class:`Call` or :class:`Name`, or ``None`` for a standalone " "``raise``. ``cause`` is the optional part for ``y`` in ``raise x from y``." msgstr "" "``raise`` 文をあらわします。 ``exc`` は送出される例外オブジェクトで、通常は :" "class:`Call` または :class:`Name`、 もしくは単独の ``raise`` では ``None`` を" "指定します。 ``cause`` はオプションで、 ``raise x from y`` の ``y`` にあたり" "ます。" #: ../../library/ast.rst:1042 msgid "" ">>> print(ast.dump(ast.parse('raise x from y'), indent=4))\n" "Module(\n" " body=[\n" " Raise(\n" " exc=Name(id='x', ctx=Load()),\n" " cause=Name(id='y', ctx=Load()))])" msgstr "" #: ../../library/ast.rst:1054 msgid "" "An assertion. ``test`` holds the condition, such as a :class:`Compare` node. " "``msg`` holds the failure message." msgstr "" "アサーションです。 ``test`` は :class:`Compare` ノードなどのような条件を保持" "します。 ``msg`` は失敗した時のメッセージを保持します。" #: ../../library/ast.rst:1057 msgid "" ">>> print(ast.dump(ast.parse('assert x,y'), indent=4))\n" "Module(\n" " body=[\n" " Assert(\n" " test=Name(id='x', ctx=Load()),\n" " msg=Name(id='y', ctx=Load()))])" msgstr "" #: ../../library/ast.rst:1069 msgid "" "Represents a ``del`` statement. ``targets`` is a list of nodes, such as :" "class:`Name`, :class:`Attribute` or :class:`Subscript` nodes." msgstr "" "``del`` 文をあらわします。 ``targets`` は :class:`Name`, :class:" "`Attribute`, :class:`Subscript` などのノードのリストです。" #: ../../library/ast.rst:1072 msgid "" ">>> print(ast.dump(ast.parse('del x,y,z'), indent=4))\n" "Module(\n" " body=[\n" " Delete(\n" " targets=[\n" " Name(id='x', ctx=Del()),\n" " Name(id='y', ctx=Del()),\n" " Name(id='z', ctx=Del())])])" msgstr "" #: ../../library/ast.rst:1086 msgid "A ``pass`` statement." msgstr "``pass`` 文をあらわします。" #: ../../library/ast.rst:1088 msgid "" ">>> print(ast.dump(ast.parse('pass'), indent=4))\n" "Module(\n" " body=[\n" " Pass()])" msgstr "" #: ../../library/ast.rst:1098 msgid "" "A :ref:`type alias ` created through the :keyword:`type` " "statement. ``name`` is the name of the alias, ``type_params`` is a list of :" "ref:`type parameters `, and ``value`` is the value of the " "type alias." msgstr "" #: ../../library/ast.rst:1103 msgid "" ">>> print(ast.dump(ast.parse('type Alias = int'), indent=4))\n" "Module(\n" " body=[\n" " TypeAlias(\n" " name=Name(id='Alias', ctx=Store()),\n" " value=Name(id='int', ctx=Load()))])" msgstr "" #: ../../library/ast.rst:1114 msgid "" "Other statements which are only applicable inside functions or loops are " "described in other sections." msgstr "" "関数またはループの内部でのみ適用可能な他の文は、別のセクションで説明します。" #: ../../library/ast.rst:1118 msgid "Imports" msgstr "インポート" #: ../../library/ast.rst:1122 msgid "An import statement. ``names`` is a list of :class:`alias` nodes." msgstr "インポート文です。 ``names`` は :class:`alias` ノードのリストです。" #: ../../library/ast.rst:1124 msgid "" ">>> print(ast.dump(ast.parse('import x,y,z'), indent=4))\n" "Module(\n" " body=[\n" " Import(\n" " names=[\n" " alias(name='x'),\n" " alias(name='y'),\n" " alias(name='z')])])" msgstr "" #: ../../library/ast.rst:1138 msgid "" "Represents ``from x import y``. ``module`` is a raw string of the 'from' " "name, without any leading dots, or ``None`` for statements such as ``from . " "import foo``. ``level`` is an integer holding the level of the relative " "import (0 means absolute import)." msgstr "" "``from x import y`` をあらわします。 ``module`` は 'from' でインポートする先" "頭がドットでないモジュール名をあらわす文字列か、または ``from . import foo`` " "のような構文の場合は ``None`` を指定します。 ``level`` は相対インポートのレベ" "ルを表す整数を保持します (0 は絶対インポートを意味します)。" #: ../../library/ast.rst:1143 msgid "" ">>> print(ast.dump(ast.parse('from y import x,y,z'), indent=4))\n" "Module(\n" " body=[\n" " ImportFrom(\n" " module='y',\n" " names=[\n" " alias(name='x'),\n" " alias(name='y'),\n" " alias(name='z')],\n" " level=0)])" msgstr "" #: ../../library/ast.rst:1159 msgid "" "Both parameters are raw strings of the names. ``asname`` can be ``None`` if " "the regular name is to be used." msgstr "" "いずれのパラメータも名前をあらわす生の文字列です。 ``asname`` は標準の名前を" "使う場合は ``None`` を指定できます。" #: ../../library/ast.rst:1162 msgid "" ">>> print(ast.dump(ast.parse('from ..foo.bar import a as b, c'), indent=4))\n" "Module(\n" " body=[\n" " ImportFrom(\n" " module='foo.bar',\n" " names=[\n" " alias(name='a', asname='b'),\n" " alias(name='c')],\n" " level=2)])" msgstr "" #: ../../library/ast.rst:1175 msgid "Control flow" msgstr "制御フロー" #: ../../library/ast.rst:1178 msgid "" "Optional clauses such as ``else`` are stored as an empty list if they're not " "present." msgstr "" "``else`` 節のようなオプションの節が存在しない場合は、空のリストとして保存され" "ます。" #: ../../library/ast.rst:1183 msgid "" "An ``if`` statement. ``test`` holds a single node, such as a :class:" "`Compare` node. ``body`` and ``orelse`` each hold a list of nodes." msgstr "" "``if`` 文です。 ``test`` は :class:`Compare` ノードなどの単一のノードを保持し" "ます。 ``body`` と ``orelse`` はそれぞれノードのリストを保持します。" #: ../../library/ast.rst:1186 msgid "" "``elif`` clauses don't have a special representation in the AST, but rather " "appear as extra :class:`If` nodes within the ``orelse`` section of the " "previous one." msgstr "" "``elif`` 節は AST において固有の表現を持たず、先行する節をあらわすノードの " "``orelse`` セクションに追加の :class:`If` ノードとして現れます。" #: ../../library/ast.rst:1190 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... if x:\n" "... ...\n" "... elif y:\n" "... ...\n" "... else:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " If(\n" " test=Name(id='x', ctx=Load()),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))],\n" " orelse=[\n" " If(\n" " test=Name(id='y', ctx=Load()),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))],\n" " orelse=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1220 msgid "" "A ``for`` loop. ``target`` holds the variable(s) the loop assigns to, as a " "single :class:`Name`, :class:`Tuple`, :class:`List`, :class:`Attribute` or :" "class:`Subscript` node. ``iter`` holds the item to be looped over, again as " "a single node. ``body`` and ``orelse`` contain lists of nodes to execute. " "Those in ``orelse`` are executed if the loop finishes normally, rather than " "via a ``break`` statement." msgstr "" #: ../../library/ast.rst:1231 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... for x in y:\n" "... ...\n" "... else:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " For(\n" " target=Name(id='x', ctx=Store()),\n" " iter=Name(id='y', ctx=Load()),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))],\n" " orelse=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])" msgstr "" #: ../../library/ast.rst:1254 msgid "" "A ``while`` loop. ``test`` holds the condition, such as a :class:`Compare` " "node." msgstr "" "``while`` ループです。 ``test`` は :class:`Compare` のような条件をあらわす" "ノードを保持します。" #: ../../library/ast.rst:1257 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... while x:\n" "... ...\n" "... else:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " While(\n" " test=Name(id='x', ctx=Load()),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))],\n" " orelse=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])" msgstr "" #: ../../library/ast.rst:1280 msgid "The ``break`` and ``continue`` statements." msgstr "``break`` 文および ``continue`` 文です。" #: ../../library/ast.rst:1282 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\\\n" "... for a in b:\n" "... if a > 5:\n" "... break\n" "... else:\n" "... continue\n" "...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " For(\n" " target=Name(id='a', ctx=Store()),\n" " iter=Name(id='b', ctx=Load()),\n" " body=[\n" " If(\n" " test=Compare(\n" " left=Name(id='a', ctx=Load()),\n" " ops=[\n" " Gt()],\n" " comparators=[\n" " Constant(value=5)]),\n" " body=[\n" " Break()],\n" " orelse=[\n" " Continue()])])])" msgstr "" #: ../../library/ast.rst:1313 msgid "" "``try`` blocks. All attributes are list of nodes to execute, except for " "``handlers``, which is a list of :class:`ExceptHandler` nodes." msgstr "" "``try`` ブロックです。 :class:`ExceptHandler` ノードのリストである " "``handlers`` を除き、全ての属性はそれぞれの節で実行するノードのリストです。" #: ../../library/ast.rst:1316 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... try:\n" "... ...\n" "... except Exception:\n" "... ...\n" "... except OtherException as e:\n" "... ...\n" "... else:\n" "... ...\n" "... finally:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Try(\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))],\n" " handlers=[\n" " ExceptHandler(\n" " type=Name(id='Exception', ctx=Load()),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))]),\n" " ExceptHandler(\n" " type=Name(id='OtherException', ctx=Load()),\n" " name='e',\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])],\n" " orelse=[\n" " Expr(\n" " value=Constant(value=Ellipsis))],\n" " finalbody=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])" msgstr "" #: ../../library/ast.rst:1358 msgid "" "``try`` blocks which are followed by ``except*`` clauses. The attributes are " "the same as for :class:`Try` but the :class:`ExceptHandler` nodes in " "``handlers`` are interpreted as ``except*`` blocks rather then ``except``." msgstr "" #: ../../library/ast.rst:1362 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... try:\n" "... ...\n" "... except* Exception:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " TryStar(\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))],\n" " handlers=[\n" " ExceptHandler(\n" " type=Name(id='Exception', ctx=Load()),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1387 msgid "" "A single ``except`` clause. ``type`` is the exception type it will match, " "typically a :class:`Name` node (or ``None`` for a catch-all ``except:`` " "clause). ``name`` is a raw string for the name to hold the exception, or " "``None`` if the clause doesn't have ``as foo``. ``body`` is a list of nodes." msgstr "" "単一の ``except`` 節をあらわします。 ``type`` はこの節にマッチする例外のタイ" "プで、典型的には :class:`Name` ノードです (``None`` を指定すると全ての例外を" "キャッチする ``except:`` 節をあらわします)。 ``name`` は例外オブジェクトを保" "持する変数の名前をあらわす生の文字列で、 ``as foo`` を持たない節の場合は " "``None`` を指定します。 ``body`` はノードのリストです。" #: ../../library/ast.rst:1392 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\\\n" "... try:\n" "... a + 1\n" "... except TypeError:\n" "... pass\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Try(\n" " body=[\n" " Expr(\n" " value=BinOp(\n" " left=Name(id='a', ctx=Load()),\n" " op=Add(),\n" " right=Constant(value=1)))],\n" " handlers=[\n" " ExceptHandler(\n" " type=Name(id='TypeError', ctx=Load()),\n" " body=[\n" " Pass()])])])" msgstr "" #: ../../library/ast.rst:1418 msgid "" "A ``with`` block. ``items`` is a list of :class:`withitem` nodes " "representing the context managers, and ``body`` is the indented block inside " "the context." msgstr "" "``with`` ブロックです。 ``items`` は :class:`withitem` ノードのリストで、コン" "テキストマネージャのリストをあらわします。また ``body`` はコンテキスト内にイ" "ンデントされたブロックです。" #: ../../library/ast.rst:1428 msgid "" "A single context manager in a ``with`` block. ``context_expr`` is the " "context manager, often a :class:`Call` node. ``optional_vars`` is a :class:" "`Name`, :class:`Tuple` or :class:`List` for the ``as foo`` part, or ``None`` " "if that isn't used." msgstr "" "``with`` ブロックにおける単一のコンテキストマネージャをあらわします。 " "``context_expr`` はコンテキストマネージャで、しばしば :class:`Call` ノードが" "設定されます。 ``optional_vars`` は ``as foo`` に相当する :class:`Name`, :" "class:`Tuple` または :class:`List` のいずれかのノードか、または、この部分が不" "要な場合は ``None`` を設定します。" #: ../../library/ast.rst:1433 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\\\n" "... with a as b, c as d:\n" "... something(b, d)\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " With(\n" " items=[\n" " withitem(\n" " context_expr=Name(id='a', ctx=Load()),\n" " optional_vars=Name(id='b', ctx=Store())),\n" " withitem(\n" " context_expr=Name(id='c', ctx=Load()),\n" " optional_vars=Name(id='d', ctx=Store()))],\n" " body=[\n" " Expr(\n" " value=Call(\n" " func=Name(id='something', ctx=Load()),\n" " args=[\n" " Name(id='b', ctx=Load()),\n" " Name(id='d', ctx=Load())]))])])" msgstr "" #: ../../library/ast.rst:1459 msgid "Pattern matching" msgstr "" #: ../../library/ast.rst:1464 msgid "" "A ``match`` statement. ``subject`` holds the subject of the match (the " "object that is being matched against the cases) and ``cases`` contains an " "iterable of :class:`match_case` nodes with the different cases." msgstr "" #: ../../library/ast.rst:1472 msgid "" "A single case pattern in a ``match`` statement. ``pattern`` contains the " "match pattern that the subject will be matched against. Note that the :class:" "`AST` nodes produced for patterns differ from those produced for " "expressions, even when they share the same syntax." msgstr "" #: ../../library/ast.rst:1477 msgid "" "The ``guard`` attribute contains an expression that will be evaluated if the " "pattern matches the subject." msgstr "" #: ../../library/ast.rst:1480 msgid "" "``body`` contains a list of nodes to execute if the pattern matches and the " "result of evaluating the guard expression is true." msgstr "" #: ../../library/ast.rst:1483 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case [x] if x>0:\n" "... ...\n" "... case tuple():\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchSequence(\n" " patterns=[\n" " MatchAs(name='x')]),\n" " guard=Compare(\n" " left=Name(id='x', ctx=Load()),\n" " ops=[\n" " Gt()],\n" " comparators=[\n" " Constant(value=0)]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))]),\n" " match_case(\n" " pattern=MatchClass(\n" " cls=Name(id='tuple', ctx=Load())),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1521 msgid "" "A match literal or value pattern that compares by equality. ``value`` is an " "expression node. Permitted value nodes are restricted as described in the " "match statement documentation. This pattern succeeds if the match subject is " "equal to the evaluated value." msgstr "" #: ../../library/ast.rst:1526 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case \"Relevant\":\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchValue(\n" " value=Constant(value='Relevant')),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1549 msgid "" "A match literal pattern that compares by identity. ``value`` is the " "singleton to be compared against: ``None``, ``True``, or ``False``. This " "pattern succeeds if the match subject is the given constant." msgstr "" #: ../../library/ast.rst:1553 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case None:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchSingleton(value=None),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1575 msgid "" "A match sequence pattern. ``patterns`` contains the patterns to be matched " "against the subject elements if the subject is a sequence. Matches a " "variable length sequence if one of the subpatterns is a ``MatchStar`` node, " "otherwise matches a fixed length sequence." msgstr "" #: ../../library/ast.rst:1580 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case [1, 2]:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchSequence(\n" " patterns=[\n" " MatchValue(\n" " value=Constant(value=1)),\n" " MatchValue(\n" " value=Constant(value=2))]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1607 msgid "" "Matches the rest of the sequence in a variable length match sequence " "pattern. If ``name`` is not ``None``, a list containing the remaining " "sequence elements is bound to that name if the overall sequence pattern is " "successful." msgstr "" #: ../../library/ast.rst:1611 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case [1, 2, *rest]:\n" "... ...\n" "... case [*_]:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchSequence(\n" " patterns=[\n" " MatchValue(\n" " value=Constant(value=1)),\n" " MatchValue(\n" " value=Constant(value=2)),\n" " MatchStar(name='rest')]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))]),\n" " match_case(\n" " pattern=MatchSequence(\n" " patterns=[\n" " MatchStar()]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1648 msgid "" "A match mapping pattern. ``keys`` is a sequence of expression nodes. " "``patterns`` is a corresponding sequence of pattern nodes. ``rest`` is an " "optional name that can be specified to capture the remaining mapping " "elements. Permitted key expressions are restricted as described in the match " "statement documentation." msgstr "" #: ../../library/ast.rst:1654 msgid "" "This pattern succeeds if the subject is a mapping, all evaluated key " "expressions are present in the mapping, and the value corresponding to each " "key matches the corresponding subpattern. If ``rest`` is not ``None``, a " "dict containing the remaining mapping elements is bound to that name if the " "overall mapping pattern is successful." msgstr "" #: ../../library/ast.rst:1660 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case {1: _, 2: _}:\n" "... ...\n" "... case {**rest}:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchMapping(\n" " keys=[\n" " Constant(value=1),\n" " Constant(value=2)],\n" " patterns=[\n" " MatchAs(),\n" " MatchAs()]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))]),\n" " match_case(\n" " pattern=MatchMapping(rest='rest'),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1695 msgid "" "A match class pattern. ``cls`` is an expression giving the nominal class to " "be matched. ``patterns`` is a sequence of pattern nodes to be matched " "against the class defined sequence of pattern matching attributes. " "``kwd_attrs`` is a sequence of additional attributes to be matched " "(specified as keyword arguments in the class pattern), ``kwd_patterns`` are " "the corresponding patterns (specified as keyword values in the class " "pattern)." msgstr "" #: ../../library/ast.rst:1702 msgid "" "This pattern succeeds if the subject is an instance of the nominated class, " "all positional patterns match the corresponding class-defined attributes, " "and any specified keyword attributes match their corresponding pattern." msgstr "" #: ../../library/ast.rst:1706 msgid "" "Note: classes may define a property that returns self in order to match a " "pattern node against the instance being matched. Several builtin types are " "also matched that way, as described in the match statement documentation." msgstr "" #: ../../library/ast.rst:1710 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case Point2D(0, 0):\n" "... ...\n" "... case Point3D(x=0, y=0, z=0):\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchClass(\n" " cls=Name(id='Point2D', ctx=Load()),\n" " patterns=[\n" " MatchValue(\n" " value=Constant(value=0)),\n" " MatchValue(\n" " value=Constant(value=0))]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))]),\n" " match_case(\n" " pattern=MatchClass(\n" " cls=Name(id='Point3D', ctx=Load()),\n" " kwd_attrs=[\n" " 'x',\n" " 'y',\n" " 'z'],\n" " kwd_patterns=[\n" " MatchValue(\n" " value=Constant(value=0)),\n" " MatchValue(\n" " value=Constant(value=0)),\n" " MatchValue(\n" " value=Constant(value=0))]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1757 msgid "" "A match \"as-pattern\", capture pattern or wildcard pattern. ``pattern`` " "contains the match pattern that the subject will be matched against. If the " "pattern is ``None``, the node represents a capture pattern (i.e a bare name) " "and will always succeed." msgstr "" #: ../../library/ast.rst:1762 msgid "" "The ``name`` attribute contains the name that will be bound if the pattern " "is successful. If ``name`` is ``None``, ``pattern`` must also be ``None`` " "and the node represents the wildcard pattern." msgstr "" #: ../../library/ast.rst:1766 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case [x] as y:\n" "... ...\n" "... case _:\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchAs(\n" " pattern=MatchSequence(\n" " patterns=[\n" " MatchAs(name='x')]),\n" " name='y'),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))]),\n" " match_case(\n" " pattern=MatchAs(),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1799 msgid "" "A match \"or-pattern\". An or-pattern matches each of its subpatterns in " "turn to the subject, until one succeeds. The or-pattern is then deemed to " "succeed. If none of the subpatterns succeed the or-pattern fails. The " "``patterns`` attribute contains a list of match pattern nodes that will be " "matched against the subject." msgstr "" #: ../../library/ast.rst:1805 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\n" "... match x:\n" "... case [x] | (y):\n" "... ...\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " Match(\n" " subject=Name(id='x', ctx=Load()),\n" " cases=[\n" " match_case(\n" " pattern=MatchOr(\n" " patterns=[\n" " MatchSequence(\n" " patterns=[\n" " MatchAs(name='x')]),\n" " MatchAs(name='y')]),\n" " body=[\n" " Expr(\n" " value=Constant(value=Ellipsis))])])])" msgstr "" #: ../../library/ast.rst:1832 msgid "Type annotations" msgstr "" #: ../../library/ast.rst:1836 msgid "" "A ``# type: ignore`` comment located at *lineno*. *tag* is the optional tag " "specified by the form ``# type: ignore ``." msgstr "" #: ../../library/ast.rst:1839 msgid "" ">>> print(ast.dump(ast.parse('x = 1 # type: ignore', type_comments=True), " "indent=4))\n" "Module(\n" " body=[\n" " Assign(\n" " targets=[\n" " Name(id='x', ctx=Store())],\n" " value=Constant(value=1))],\n" " type_ignores=[\n" " TypeIgnore(lineno=1, tag='')])\n" ">>> print(ast.dump(ast.parse('x: bool = 1 # type: ignore[assignment]', " "type_comments=True), indent=4))\n" "Module(\n" " body=[\n" " AnnAssign(\n" " target=Name(id='x', ctx=Store()),\n" " annotation=Name(id='bool', ctx=Load()),\n" " value=Constant(value=1),\n" " simple=1)],\n" " type_ignores=[\n" " TypeIgnore(lineno=1, tag='[assignment]')])" msgstr "" #: ../../library/ast.rst:1862 msgid "" ":class:`!TypeIgnore` nodes are not generated when the *type_comments* " "parameter is set to ``False`` (default). See :func:`ast.parse` for more " "details." msgstr "" #: ../../library/ast.rst:1870 msgid "Type parameters" msgstr "" #: ../../library/ast.rst:1872 msgid "" ":ref:`Type parameters ` can exist on classes, functions, and " "type aliases." msgstr "" #: ../../library/ast.rst:1877 msgid "" "A :class:`typing.TypeVar`. ``name`` is the name of the type variable. " "``bound`` is the bound or constraints, if any. If ``bound`` is a :class:" "`Tuple`, it represents constraints; otherwise it represents the bound. " "``default_value`` is the default value; if the :class:`!TypeVar` has no " "default, this attribute will be set to ``None``." msgstr "" #: ../../library/ast.rst:1883 msgid "" ">>> print(ast.dump(ast.parse(\"type Alias[T: int = bool] = list[T]\"), " "indent=4))\n" "Module(\n" " body=[\n" " TypeAlias(\n" " name=Name(id='Alias', ctx=Store()),\n" " type_params=[\n" " TypeVar(\n" " name='T',\n" " bound=Name(id='int', ctx=Load()),\n" " default_value=Name(id='bool', ctx=Load()))],\n" " value=Subscript(\n" " value=Name(id='list', ctx=Load()),\n" " slice=Name(id='T', ctx=Load()),\n" " ctx=Load()))])" msgstr "" #: ../../library/ast.rst:1902 ../../library/ast.rst:1937 #: ../../library/ast.rst:1969 msgid "Added the *default_value* parameter." msgstr "" #: ../../library/ast.rst:1907 msgid "" "A :class:`typing.ParamSpec`. ``name`` is the name of the parameter " "specification. ``default_value`` is the default value; if the :class:`!" "ParamSpec` has no default, this attribute will be set to ``None``." msgstr "" #: ../../library/ast.rst:1911 msgid "" ">>> print(ast.dump(ast.parse(\"type Alias[**P = [int, str]] = Callable[P, " "int]\"), indent=4))\n" "Module(\n" " body=[\n" " TypeAlias(\n" " name=Name(id='Alias', ctx=Store()),\n" " type_params=[\n" " ParamSpec(\n" " name='P',\n" " default_value=List(\n" " elts=[\n" " Name(id='int', ctx=Load()),\n" " Name(id='str', ctx=Load())],\n" " ctx=Load()))],\n" " value=Subscript(\n" " value=Name(id='Callable', ctx=Load()),\n" " slice=Tuple(\n" " elts=[\n" " Name(id='P', ctx=Load()),\n" " Name(id='int', ctx=Load())],\n" " ctx=Load()),\n" " ctx=Load()))])" msgstr "" #: ../../library/ast.rst:1942 msgid "" "A :class:`typing.TypeVarTuple`. ``name`` is the name of the type variable " "tuple. ``default_value`` is the default value; if the :class:`!TypeVarTuple` " "has no default, this attribute will be set to ``None``." msgstr "" #: ../../library/ast.rst:1946 msgid "" ">>> print(ast.dump(ast.parse(\"type Alias[*Ts = ()] = tuple[*Ts]\"), " "indent=4))\n" "Module(\n" " body=[\n" " TypeAlias(\n" " name=Name(id='Alias', ctx=Store()),\n" " type_params=[\n" " TypeVarTuple(\n" " name='Ts',\n" " default_value=Tuple(ctx=Load()))],\n" " value=Subscript(\n" " value=Name(id='tuple', ctx=Load()),\n" " slice=Tuple(\n" " elts=[\n" " Starred(\n" " value=Name(id='Ts', ctx=Load()),\n" " ctx=Load())],\n" " ctx=Load()),\n" " ctx=Load()))])" msgstr "" #: ../../library/ast.rst:1973 msgid "Function and class definitions" msgstr "関数およびクラス定義" #: ../../library/ast.rst:1977 msgid "A function definition." msgstr "関数定義です。" #: ../../library/ast.rst:1979 msgid "``name`` is a raw string of the function name." msgstr "``name`` は関数名をあらわす生の文字列です。" #: ../../library/ast.rst:1980 msgid "``args`` is an :class:`arguments` node." msgstr "``args`` は引数をあらわす :class:`arguments` ノードです。" #: ../../library/ast.rst:1981 msgid "``body`` is the list of nodes inside the function." msgstr "``body`` は関数の本体をあらわすノードのリストです。" #: ../../library/ast.rst:1982 msgid "" "``decorator_list`` is the list of decorators to be applied, stored outermost " "first (i.e. the first in the list will be applied last)." msgstr "" "``decorator_list`` は関数に適用されるデコレータのリストで、外側のデコレータが" "リストの先頭に保存されます (すなわち、リストの先頭にあるデコレータが最後に適" "用されます)。" #: ../../library/ast.rst:1984 msgid "``returns`` is the return annotation." msgstr "``returns`` は戻り値に対する注釈です。" #: ../../library/ast.rst:1985 ../../library/ast.rst:2148 msgid "``type_params`` is a list of :ref:`type parameters `." msgstr "" #: ../../library/ast.rst:1991 ../../library/ast.rst:2175 #: ../../library/ast.rst:2186 msgid "Added ``type_params``." msgstr "" #: ../../library/ast.rst:1997 msgid "" "``lambda`` is a minimal function definition that can be used inside an " "expression. Unlike :class:`FunctionDef`, ``body`` holds a single node." msgstr "" "``lambda`` は式の中で使うことができる最小限の関数定義です。 :class:" "`FunctionDef` ノードと異なり、 ``body`` は単一のノードとなります。" #: ../../library/ast.rst:2000 msgid "" ">>> print(ast.dump(ast.parse('lambda x,y: ...'), indent=4))\n" "Module(\n" " body=[\n" " Expr(\n" " value=Lambda(\n" " args=arguments(\n" " args=[\n" " arg(arg='x'),\n" " arg(arg='y')]),\n" " body=Constant(value=Ellipsis)))])" msgstr "" #: ../../library/ast.rst:2016 msgid "The arguments for a function." msgstr "関数の引数" #: ../../library/ast.rst:2018 msgid "" "``posonlyargs``, ``args`` and ``kwonlyargs`` are lists of :class:`arg` nodes." msgstr "" "``posonlyargs``, ``args`` および ``kwonlyargs`` はそれぞれ :class:`arg` ノー" "ドのリストです。" #: ../../library/ast.rst:2019 msgid "" "``vararg`` and ``kwarg`` are single :class:`arg` nodes, referring to the " "``*args, **kwargs`` parameters." msgstr "" "``vararg`` と ``kwarg`` はそれぞれ単一の :class:`arg` ノードで、 ``*args, " "**kwargs`` パラメータに相当します。" #: ../../library/ast.rst:2021 msgid "" "``kw_defaults`` is a list of default values for keyword-only arguments. If " "one is ``None``, the corresponding argument is required." msgstr "" "``kw_defaults`` はキーワード専用引数に対するデフォルト値のリストです。値が " "``None`` の場合、対応する引数は必須となります。" #: ../../library/ast.rst:2023 msgid "" "``defaults`` is a list of default values for arguments that can be passed " "positionally. If there are fewer defaults, they correspond to the last n " "arguments." msgstr "" "``defaults`` は位置引数として渡すことのできる引数に対するデフォルト値のリスト" "です。デフォルト値の数nが位置引数の数より少ない場合、それらは最後のn個の引数" "に割り当てられます。" #: ../../library/ast.rst:2030 msgid "" "A single argument in a list. ``arg`` is a raw string of the argument name; " "``annotation`` is its annotation, such as a :class:`Name` node." msgstr "" #: ../../library/ast.rst:2035 msgid "" "``type_comment`` is an optional string with the type annotation as a comment" msgstr "" "``type_comment`` はコメントとして型アノテーションをあらわすオプション文字列で" "す。" #: ../../library/ast.rst:2037 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\\\n" "... @decorator1\n" "... @decorator2\n" "... def f(a: 'annotation', b=1, c=2, *d, e, f=3, **g) -> 'return " "annotation':\n" "... pass\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " FunctionDef(\n" " name='f',\n" " args=arguments(\n" " args=[\n" " arg(\n" " arg='a',\n" " annotation=Constant(value='annotation')),\n" " arg(arg='b'),\n" " arg(arg='c')],\n" " vararg=arg(arg='d'),\n" " kwonlyargs=[\n" " arg(arg='e'),\n" " arg(arg='f')],\n" " kw_defaults=[\n" " None,\n" " Constant(value=3)],\n" " kwarg=arg(arg='g'),\n" " defaults=[\n" " Constant(value=1),\n" " Constant(value=2)]),\n" " body=[\n" " Pass()],\n" " decorator_list=[\n" " Name(id='decorator1', ctx=Load()),\n" " Name(id='decorator2', ctx=Load())],\n" " returns=Constant(value='return annotation'))])" msgstr "" #: ../../library/ast.rst:2077 msgid "A ``return`` statement." msgstr "``return`` 文です。" #: ../../library/ast.rst:2079 msgid "" ">>> print(ast.dump(ast.parse('return 4'), indent=4))\n" "Module(\n" " body=[\n" " Return(\n" " value=Constant(value=4))])" msgstr "" #: ../../library/ast.rst:2091 msgid "" "A ``yield`` or ``yield from`` expression. Because these are expressions, " "they must be wrapped in an :class:`Expr` node if the value sent back is not " "used." msgstr "" #: ../../library/ast.rst:2094 msgid "" ">>> print(ast.dump(ast.parse('yield x'), indent=4))\n" "Module(\n" " body=[\n" " Expr(\n" " value=Yield(\n" " value=Name(id='x', ctx=Load())))])\n" "\n" ">>> print(ast.dump(ast.parse('yield from x'), indent=4))\n" "Module(\n" " body=[\n" " Expr(\n" " value=YieldFrom(\n" " value=Name(id='x', ctx=Load())))])" msgstr "" #: ../../library/ast.rst:2114 msgid "" "``global`` and ``nonlocal`` statements. ``names`` is a list of raw strings." msgstr "" "``global`` および ``nonlocal`` 文です。 ``names`` は生の文字列のリストです。" #: ../../library/ast.rst:2116 msgid "" ">>> print(ast.dump(ast.parse('global x,y,z'), indent=4))\n" "Module(\n" " body=[\n" " Global(\n" " names=[\n" " 'x',\n" " 'y',\n" " 'z'])])\n" "\n" ">>> print(ast.dump(ast.parse('nonlocal x,y,z'), indent=4))\n" "Module(\n" " body=[\n" " Nonlocal(\n" " names=[\n" " 'x',\n" " 'y',\n" " 'z'])])" msgstr "" #: ../../library/ast.rst:2139 msgid "A class definition." msgstr "クラス定義です。" #: ../../library/ast.rst:2141 msgid "``name`` is a raw string for the class name" msgstr "``name`` はクラス名をあらわす生の文字列です。" #: ../../library/ast.rst:2142 msgid "``bases`` is a list of nodes for explicitly specified base classes." msgstr "``bases`` は明示的に指定された基底クラスをあらわすノードのリストです。" #: ../../library/ast.rst:2143 msgid "" "``keywords`` is a list of :class:`.keyword` nodes, principally for " "'metaclass'. Other keywords will be passed to the metaclass, as per :pep:" "`3115`." msgstr "" #: ../../library/ast.rst:2145 msgid "" "``body`` is a list of nodes representing the code within the class " "definition." msgstr "``body`` はクラス定義に含まれるコードをあらわすノードのリストです。" #: ../../library/ast.rst:2147 msgid "``decorator_list`` is a list of nodes, as in :class:`FunctionDef`." msgstr "" "``decorator_list`` はノードのリストで、関数定義 :class:`FunctionDef` の場合と" "同様に解釈されます。" #: ../../library/ast.rst:2150 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\\\n" "... @decorator1\n" "... @decorator2\n" "... class Foo(base1, base2, metaclass=meta):\n" "... pass\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " ClassDef(\n" " name='Foo',\n" " bases=[\n" " Name(id='base1', ctx=Load()),\n" " Name(id='base2', ctx=Load())],\n" " keywords=[\n" " keyword(\n" " arg='metaclass',\n" " value=Name(id='meta', ctx=Load()))],\n" " body=[\n" " Pass()],\n" " decorator_list=[\n" " Name(id='decorator1', ctx=Load()),\n" " Name(id='decorator2', ctx=Load())])])" msgstr "" #: ../../library/ast.rst:2179 msgid "Async and await" msgstr "async と await" #: ../../library/ast.rst:2183 msgid "" "An ``async def`` function definition. Has the same fields as :class:" "`FunctionDef`." msgstr "" "``async def`` 形式の関数定義です。通常の関数定義 :class:`FunctionDef` と同じ" "フィールドを持ちます。" #: ../../library/ast.rst:2192 msgid "" "An ``await`` expression. ``value`` is what it waits for. Only valid in the " "body of an :class:`AsyncFunctionDef`." msgstr "" "``await`` 式をあらわします。 ``value`` は待ち受ける値です。 :class:" "`AsyncFunctionDef` の本体 (body) の中でのみ有効です。" #: ../../library/ast.rst:2195 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\\\n" "... async def f():\n" "... await other_func()\n" "... \"\"\"), indent=4))\n" "Module(\n" " body=[\n" " AsyncFunctionDef(\n" " name='f',\n" " args=arguments(),\n" " body=[\n" " Expr(\n" " value=Await(\n" " value=Call(\n" " func=Name(id='other_func', ctx=Load()))))])])" msgstr "" #: ../../library/ast.rst:2216 msgid "" "``async for`` loops and ``async with`` context managers. They have the same " "fields as :class:`For` and :class:`With`, respectively. Only valid in the " "body of an :class:`AsyncFunctionDef`." msgstr "" "``async for`` ループと ``async with`` コンテキストマネージャです。それぞれ :" "class:`For` および :class:`With` と同じフィールドを持ちます。 :class:" "`AsyncFunctionDef` の本体 (body) の中でのみ有効です。" #: ../../library/ast.rst:2221 msgid "" "When a string is parsed by :func:`ast.parse`, operator nodes (subclasses of :" "class:`ast.operator`, :class:`ast.unaryop`, :class:`ast.cmpop`, :class:`ast." "boolop` and :class:`ast.expr_context`) on the returned tree will be " "singletons. Changes to one will be reflected in all other occurrences of the " "same value (for example, :class:`ast.Add`)." msgstr "" #: ../../library/ast.rst:2229 msgid ":mod:`!ast` helpers" msgstr "" #: ../../library/ast.rst:2231 msgid "" "Apart from the node classes, the :mod:`!ast` module defines these utility " "functions and classes for traversing abstract syntax trees:" msgstr "" #: ../../library/ast.rst:2236 msgid "" "Parse the source into an AST node. Equivalent to ``compile(source, " "filename, mode, flags=FLAGS_VALUE, optimize=optimize)``, where " "``FLAGS_VALUE`` is ``ast.PyCF_ONLY_AST`` if ``optimize <= 0`` and ``ast." "PyCF_OPTIMIZED_AST`` otherwise." msgstr "" #: ../../library/ast.rst:2241 msgid "" "If ``type_comments=True`` is given, the parser is modified to check and " "return type comments as specified by :pep:`484` and :pep:`526`. This is " "equivalent to adding :data:`ast.PyCF_TYPE_COMMENTS` to the flags passed to :" "func:`compile`. This will report syntax errors for misplaced type " "comments. Without this flag, type comments will be ignored, and the " "``type_comment`` field on selected AST nodes will always be ``None``. In " "addition, the locations of ``# type: ignore`` comments will be returned as " "the ``type_ignores`` attribute of :class:`Module` (otherwise it is always an " "empty list)." msgstr "" #: ../../library/ast.rst:2251 msgid "" "In addition, if ``mode`` is ``'func_type'``, the input syntax is modified to " "correspond to :pep:`484` \"signature type comments\", e.g. ``(str, int) -> " "List[str]``." msgstr "" "さらに ``mode`` が ``'func_type'`` の場合、入力構文は、たとえば ``(str, int) " "-> List[str]`` のような :pep:`484` の \"シグネチャ型コメント (signature type " "comments)\" に対応するように修正されます。" #: ../../library/ast.rst:2255 msgid "" "Setting ``feature_version`` to a tuple ``(major, minor)`` will result in a " "\"best-effort\" attempt to parse using that Python version's grammar. For " "example, setting ``feature_version=(3, 9)`` will attempt to disallow parsing " "of :keyword:`match` statements. Currently ``major`` must equal to ``3``. The " "lowest supported version is ``(3, 7)`` (and this may increase in future " "Python versions); the highest is ``sys.version_info[0:2]``. \"Best-effort\" " "attempt means there is no guarantee that the parse (or success of the parse) " "is the same as when run on the Python version corresponding to " "``feature_version``." msgstr "" #: ../../library/ast.rst:2265 msgid "" "If source contains a null character (``\\0``), :exc:`ValueError` is raised." msgstr "" #: ../../library/ast.rst:2268 msgid "" "Note that successfully parsing source code into an AST object doesn't " "guarantee that the source code provided is valid Python code that can be " "executed as the compilation step can raise further :exc:`SyntaxError` " "exceptions. For instance, the source ``return 42`` generates a valid AST " "node for a return statement, but it cannot be compiled alone (it needs to be " "inside a function node)." msgstr "" #: ../../library/ast.rst:2275 msgid "" "In particular, :func:`ast.parse` won't do any scoping checks, which the " "compilation step does." msgstr "" #: ../../library/ast.rst:2279 msgid "" "It is possible to crash the Python interpreter with a sufficiently large/" "complex string due to stack depth limitations in Python's AST compiler." msgstr "" "十分に大きい文字列や複雑な文字列によって Python の抽象構文木コンパイラのス" "タックの深さの限界を越えることで、 Python インタプリタをクラッシュさせること" "ができます。" #: ../../library/ast.rst:2283 msgid "Added ``type_comments``, ``mode='func_type'`` and ``feature_version``." msgstr "" "``type_comments``、``mode='func_type'``、``feature_version`` が追加されまし" "た。" #: ../../library/ast.rst:2286 msgid "" "The minimum supported version for ``feature_version`` is now ``(3, 7)``. The " "``optimize`` argument was added." msgstr "" #: ../../library/ast.rst:2293 msgid "" "Unparse an :class:`ast.AST` object and generate a string with code that " "would produce an equivalent :class:`ast.AST` object if parsed back with :" "func:`ast.parse`." msgstr "" ":class:`ast.AST` オブジェクトを逆に構文解析して、 :func:`ast.parse` が元の :" "class:`ast.AST` と等価なオブジェクトを生成できるような文字列を生成します。" #: ../../library/ast.rst:2298 msgid "" "The produced code string will not necessarily be equal to the original code " "that generated the :class:`ast.AST` object (without any compiler " "optimizations, such as constant tuples/frozensets)." msgstr "" "生成されたコード文字列は、生成元のコードである :class:`ast.AST` オブジェクト" "と必ずしも等価であるとは限りません (定数タプルや frozenset などに対するコンパ" "イラ最適化なしのコードです)。" #: ../../library/ast.rst:2303 msgid "" "Trying to unparse a highly complex expression would result with :exc:" "`RecursionError`." msgstr "" "非常に複雑な式を逆構文解析すると :exc:`RecursionError` となることがあります。" #: ../../library/ast.rst:2311 msgid "" "Evaluate an expression node or a string containing only a Python literal or " "container display. The string or node provided may only consist of the " "following Python literal structures: strings, bytes, numbers, tuples, lists, " "dicts, sets, booleans, ``None`` and ``Ellipsis``." msgstr "" "Python のリテラルやコンテナ表現のみを含む式ノードまたは文字列を評価します。与" "えられる文字列またはノードは次の Python リテラル構造のみからなるものに限られ" "ます: 文字列、バイト列、数、タプル、リスト、辞書、集合、ブール値、``None``、" "``Ellipsis``。" #: ../../library/ast.rst:2316 msgid "" "This can be used for evaluating strings containing Python values without the " "need to parse the values oneself. It is not capable of evaluating " "arbitrarily complex expressions, for example involving operators or indexing." msgstr "" "この関数は Python の式を含んだ文字列を、値自身を解析することなしに評価するの" "に使えます。この関数は、例えば演算や添え字を含んだ任意の複雑な表現を評価する" "のには使えません。" #: ../../library/ast.rst:2321 msgid "" "This function had been documented as \"safe\" in the past without defining " "what that meant. That was misleading. This is specifically designed not to " "execute Python code, unlike the more general :func:`eval`. There is no " "namespace, no name lookups, or ability to call out. But it is not free from " "attack: A relatively small input can lead to memory exhaustion or to C stack " "exhaustion, crashing the process. There is also the possibility for " "excessive CPU consumption denial of service on some inputs. Calling it on " "untrusted data is thus not recommended." msgstr "" #: ../../library/ast.rst:2331 msgid "" "It is possible to crash the Python interpreter due to stack depth " "limitations in Python's AST compiler." msgstr "" "Python の抽象構文木コンパイラのスタックの深さの限界を越えることで、 Python イ" "ンタプリタをクラッシュさせる可能性があります。" #: ../../library/ast.rst:2334 msgid "" "It can raise :exc:`ValueError`, :exc:`TypeError`, :exc:`SyntaxError`, :exc:" "`MemoryError` and :exc:`RecursionError` depending on the malformed input." msgstr "" #: ../../library/ast.rst:2338 msgid "Now allows bytes and set literals." msgstr "バイト列リテラルと集合リテラルが受け取れるようになりました。" #: ../../library/ast.rst:2341 msgid "Now supports creating empty sets with ``'set()'``." msgstr "``'set()'`` による空の集合の生成をサポートするようになりました。" #: ../../library/ast.rst:2344 msgid "For string inputs, leading spaces and tabs are now stripped." msgstr "" #: ../../library/ast.rst:2350 msgid "" "Return the docstring of the given *node* (which must be a :class:" "`FunctionDef`, :class:`AsyncFunctionDef`, :class:`ClassDef`, or :class:" "`Module` node), or ``None`` if it has no docstring. If *clean* is true, " "clean up the docstring's indentation with :func:`inspect.cleandoc`." msgstr "" "与えられた *node* (これは :class:`FunctionDef`, :class:`AsyncFunctionDef`, :" "class:`ClassDef`, :class:`Module` のいずれかのノードでなければなりません) の" "ドキュメント文字列を返します。もしドキュメント文字列が無ければ ``None`` を返" "します。 *clean* が真ならば、ドキュメント文字列のインデントを :func:`inspect." "cleandoc` を用いて一掃します。" #: ../../library/ast.rst:2356 msgid ":class:`AsyncFunctionDef` is now supported." msgstr ":class:`AsyncFunctionDef` がサポートされました。" #: ../../library/ast.rst:2362 msgid "" "Get source code segment of the *source* that generated *node*. If some " "location information (:attr:`~ast.AST.lineno`, :attr:`~ast.AST.end_lineno`, :" "attr:`~ast.AST.col_offset`, or :attr:`~ast.AST.end_col_offset`) is missing, " "return ``None``." msgstr "" #: ../../library/ast.rst:2366 msgid "" "If *padded* is ``True``, the first line of a multi-line statement will be " "padded with spaces to match its original position." msgstr "" "*padded* が ``True`` の場合、複数行にわたる文の最初の行が元の位置に一致するよ" "うに空白文字でパディングされます。" #: ../../library/ast.rst:2374 msgid "" "When you compile a node tree with :func:`compile`, the compiler expects :" "attr:`~ast.AST.lineno` and :attr:`~ast.AST.col_offset` attributes for every " "node that supports them. This is rather tedious to fill in for generated " "nodes, so this helper adds these attributes recursively where not already " "set, by setting them to the values of the parent node. It works recursively " "starting at *node*." msgstr "" #: ../../library/ast.rst:2383 msgid "" "Increment the line number and end line number of each node in the tree " "starting at *node* by *n*. This is useful to \"move code\" to a different " "location in a file." msgstr "" "*node* で始まるツリー内の各ノードの行番号と終了行番号を *n* ずつ増やします。" "これはファイルの中で別の場所に \"コードを移動する\" ときに便利です。" #: ../../library/ast.rst:2390 msgid "" "Copy source location (:attr:`~ast.AST.lineno`, :attr:`~ast.AST.col_offset`, :" "attr:`~ast.AST.end_lineno`, and :attr:`~ast.AST.end_col_offset`) from " "*old_node* to *new_node* if possible, and return *new_node*." msgstr "" #: ../../library/ast.rst:2397 msgid "" "Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields`` " "that is present on *node*." msgstr "" "*node* にある ``node._fields`` のそれぞれのフィールドを ``(フィールド名, " "値)`` のタプルとして yield します。" #: ../../library/ast.rst:2403 msgid "" "Yield all direct child nodes of *node*, that is, all fields that are nodes " "and all items of fields that are lists of nodes." msgstr "" "*node* の直接の子ノード全てを yield します。すなわち、yield されるのは、ノー" "ドであるような全てのフィールドおよびノードのリストであるようなフィールドの全" "てのアイテムです。" #: ../../library/ast.rst:2409 msgid "" "Recursively yield all descendant nodes in the tree starting at *node* " "(including *node* itself), in no specified order. This is useful if you " "only want to modify nodes in place and don't care about the context." msgstr "" "*node* の全ての子孫ノード(*node* 自体を含む)を再帰的に yield します。順番は決" "められていません。この関数はノードをその場で変更するだけで文脈を気にしないよ" "うな場合に便利です。" #: ../../library/ast.rst:2416 msgid "" "A node visitor base class that walks the abstract syntax tree and calls a " "visitor function for every node found. This function may return a value " "which is forwarded by the :meth:`visit` method." msgstr "" "抽象構文木を渡り歩いてビジター関数を見つけたノードごとに呼び出すノード・ビジ" "ターの基底クラスです。この関数は :meth:`visit` メソッドに送られる値を返しても" "かまいません。" #: ../../library/ast.rst:2420 msgid "" "This class is meant to be subclassed, with the subclass adding visitor " "methods." msgstr "" "このクラスはビジター・メソッドを付け加えたサブクラスを派生させることを意図し" "ています。" #: ../../library/ast.rst:2425 msgid "" "Visit a node. The default implementation calls the method called :samp:" "`self.visit_{classname}` where *classname* is the name of the node class, " "or :meth:`generic_visit` if that method doesn't exist." msgstr "" "ノードを訪れます。デフォルトの実装では :samp:`self.visit_{classname}` という" "メソッド (ここで *classname* はノードのクラス名です) を呼び出すか、そのメソッ" "ドがなければ :meth:`generic_visit` を呼び出します。" #: ../../library/ast.rst:2431 msgid "This visitor calls :meth:`visit` on all children of the node." msgstr "このビジターはノードの全ての子について :meth:`visit` を呼び出します。" #: ../../library/ast.rst:2433 msgid "" "Note that child nodes of nodes that have a custom visitor method won't be " "visited unless the visitor calls :meth:`generic_visit` or visits them itself." msgstr "" "注意して欲しいのは、専用のビジター・メソッドを具えたノードの子ノードは、この" "ビジターが :meth:`generic_visit` を呼び出すかそれ自身で子ノードを訪れない限り" "訪れられないということです。" #: ../../library/ast.rst:2439 msgid "Handles all constant nodes." msgstr "" #: ../../library/ast.rst:2441 msgid "" "Don't use the :class:`NodeVisitor` if you want to apply changes to nodes " "during traversal. For this a special visitor exists (:class:" "`NodeTransformer`) that allows modifications." msgstr "" "トラバースの途中でノードを変化させたいならば :class:`NodeVisitor` を使っては" "いけません。そうした目的のために変更を許す特別なビジター (:class:" "`NodeTransformer`) があります。" #: ../../library/ast.rst:2447 msgid "" "Methods :meth:`!visit_Num`, :meth:`!visit_Str`, :meth:`!visit_Bytes`, :meth:" "`!visit_NameConstant` and :meth:`!visit_Ellipsis` will not be called in " "Python 3.14+. Add the :meth:`visit_Constant` method instead to handle all " "constant nodes." msgstr "" #: ../../library/ast.rst:2455 msgid "" "A :class:`NodeVisitor` subclass that walks the abstract syntax tree and " "allows modification of nodes." msgstr "" ":class:`NodeVisitor` のサブクラスで抽象構文木を渡り歩きながらノードを変更する" "ことを許すものです。" #: ../../library/ast.rst:2458 msgid "" "The :class:`NodeTransformer` will walk the AST and use the return value of " "the visitor methods to replace or remove the old node. If the return value " "of the visitor method is ``None``, the node will be removed from its " "location, otherwise it is replaced with the return value. The return value " "may be the original node in which case no replacement takes place." msgstr "" ":class:`NodeTransformer` は抽象構文木(AST)を渡り歩き、ビジター・メソッドの戻" "り値を使って古いノードを置き換えたり削除したりします。ビジター・メソッドの戻" "り値が ``None`` ならば、ノードはその場から取り去られ、そうでなければ戻り値で" "置き換えられます。置き換えない場合は戻り値が元のノードそのものであってもかま" "いません。" #: ../../library/ast.rst:2464 msgid "" "Here is an example transformer that rewrites all occurrences of name lookups " "(``foo``) to ``data['foo']``::" msgstr "" "それでは例を示しましょう。Name (たとえば ``foo``) を見つけるたび全て " "``data['foo']`` に書き換える変換器 (transformer) です::" #: ../../library/ast.rst:2467 msgid "" "class RewriteName(NodeTransformer):\n" "\n" " def visit_Name(self, node):\n" " return Subscript(\n" " value=Name(id='data', ctx=Load()),\n" " slice=Constant(value=node.id),\n" " ctx=node.ctx\n" " )" msgstr "" #: ../../library/ast.rst:2476 msgid "" "Keep in mind that if the node you're operating on has child nodes you must " "either transform the child nodes yourself or call the :meth:`~ast." "NodeVisitor.generic_visit` method for the node first." msgstr "" #: ../../library/ast.rst:2480 msgid "" "For nodes that were part of a collection of statements (that applies to all " "statement nodes), the visitor may also return a list of nodes rather than " "just a single node." msgstr "" "文のコレクションであるようなノード (全ての文のノードが当てはまります) に対し" "て、このビジターは単独のノードではなくノードのリストを返すかもしれません。" #: ../../library/ast.rst:2484 msgid "" "If :class:`NodeTransformer` introduces new nodes (that weren't part of " "original tree) without giving them location information (such as :attr:`~ast." "AST.lineno`), :func:`fix_missing_locations` should be called with the new " "sub-tree to recalculate the location information::" msgstr "" #: ../../library/ast.rst:2489 msgid "" "tree = ast.parse('foo', mode='eval')\n" "new_tree = fix_missing_locations(RewriteName().visit(tree))" msgstr "" #: ../../library/ast.rst:2492 msgid "Usually you use the transformer like this::" msgstr "たいてい、変換器の使い方は次のようになります::" #: ../../library/ast.rst:2494 msgid "node = YourTransformer().visit(node)" msgstr "" #: ../../library/ast.rst:2499 msgid "" "Return a formatted dump of the tree in *node*. This is mainly useful for " "debugging purposes. If *annotate_fields* is true (by default), the returned " "string will show the names and the values for fields. If *annotate_fields* " "is false, the result string will be more compact by omitting unambiguous " "field names. Attributes such as line numbers and column offsets are not " "dumped by default. If this is wanted, *include_attributes* can be set to " "true." msgstr "" "*node* 内のツリーのフォーマットされたダンプを返します。主な使い道はデバッグで" "す。 *annotate_fields* が true の場合 (デフォルト)、返される文字列はフィール" "ドの名前と値を示します。 *annotate_fields* が false の場合、あいまいさのない" "フィールド名を省略することにより、結果文字列はよりコンパクトになります。行番" "号や列オフセットのような属性はデフォルトではダンプされません。これが必要であ" "れば、 *include_attributes* を true にすると表示できます。" #: ../../library/ast.rst:2507 msgid "" "If *indent* is a non-negative integer or string, then the tree will be " "pretty-printed with that indent level. An indent level of 0, negative, or " "``\"\"`` will only insert newlines. ``None`` (the default) selects the " "single line representation. Using a positive integer indent indents that " "many spaces per level. If *indent* is a string (such as ``\"\\t\"``), that " "string is used to indent each level." msgstr "" "*indent* が非負の整数または文字列の場合、ツリーは指定されたインデントレベルで" "整形されて出力されます (pretty-printed)。インデントレベルがゼロ、負の数、また" "は ``\"\"`` の場合は改行だけを挿入します。 ``None`` (デフォルト値) は単一行で" "の表記になります。正の整数を指定すると各インデントレベルでその数だけの空白で" "インデントされます。 *indent* が文字列 (``\"\\t\"`` など) の場合、その文字列" "が各レベルのインデントに使われます。" #: ../../library/ast.rst:2514 msgid "" "If *show_empty* is false (the default), optional empty lists will be omitted " "from the output. Optional ``None`` values are always omitted." msgstr "" #: ../../library/ast.rst:2518 msgid "Added the *indent* option." msgstr "*indent* オプションを追加しました。" #: ../../library/ast.rst:2521 msgid "Added the *show_empty* option." msgstr "" #: ../../library/ast.rst:2524 msgid "" ">>> print(ast.dump(ast.parse(\"\"\"\\\n" "... async def f():\n" "... await other_func()\n" "... \"\"\"), indent=4, show_empty=True))\n" "Module(\n" " body=[\n" " AsyncFunctionDef(\n" " name='f',\n" " args=arguments(\n" " posonlyargs=[],\n" " args=[],\n" " kwonlyargs=[],\n" " kw_defaults=[],\n" " defaults=[]),\n" " body=[\n" " Expr(\n" " value=Await(\n" " value=Call(\n" " func=Name(id='other_func', ctx=Load()),\n" " args=[],\n" " keywords=[])))],\n" " decorator_list=[],\n" " type_params=[])],\n" " type_ignores=[])" msgstr "" #: ../../library/ast.rst:2555 msgid "Compiler flags" msgstr "" #: ../../library/ast.rst:2557 msgid "" "The following flags may be passed to :func:`compile` in order to change " "effects on the compilation of a program:" msgstr "" "以下のフラグはプログラムのコンパイルにおける効果を変更するために :func:" "`compile` に渡すことができます:" #: ../../library/ast.rst:2562 msgid "" "Enables support for top-level ``await``, ``async for``, ``async with`` and " "async comprehensions." msgstr "" "トップレベルの ``await``, ``async for``, ``async with`` および async 内包表記" "のサポートを有効化します。" #: ../../library/ast.rst:2569 msgid "" "Generates and returns an abstract syntax tree instead of returning a " "compiled code object." msgstr "" "コンパイルされたコードオブジェクトの代わりに抽象構文木を生成して返します。" #: ../../library/ast.rst:2574 msgid "" "The returned AST is optimized according to the *optimize* argument in :func:" "`compile` or :func:`ast.parse`." msgstr "" #: ../../library/ast.rst:2581 msgid "" "Enables support for :pep:`484` and :pep:`526` style type comments (``# type: " "``, ``# type: ignore ``)." msgstr "" ":pep:`484` および :pep:`526` 形式の型コメント (``# type: ``, ``# type: " "ignore ``) のサポートを有効化します。" #: ../../library/ast.rst:2589 msgid "Recursively compares two ASTs." msgstr "" #: ../../library/ast.rst:2591 msgid "" "*compare_attributes* affects whether AST attributes are considered in the " "comparison. If *compare_attributes* is ``False`` (default), then attributes " "are ignored. Otherwise they must all be equal. This option is useful to " "check whether the ASTs are structurally equal but differ in whitespace or " "similar details. Attributes include line numbers and column offsets." msgstr "" #: ../../library/ast.rst:2604 msgid "Command-line usage" msgstr "コマンドラインでの使用" #: ../../library/ast.rst:2608 msgid "" "The :mod:`!ast` module can be executed as a script from the command line. It " "is as simple as:" msgstr "" #: ../../library/ast.rst:2611 msgid "python -m ast [-m ] [-a] [infile]" msgstr "" #: ../../library/ast.rst:2615 msgid "The following options are accepted:" msgstr "以下のオプションが使用できます:" #: ../../library/ast.rst:2621 msgid "Show the help message and exit." msgstr "ヘルプメッセージを表示して終了します。" #: ../../library/ast.rst:2626 msgid "" "Specify what kind of code must be compiled, like the *mode* argument in :" "func:`parse`." msgstr "" ":func:`parse` 関数の *mode* 引数と同様、コンパイルするコードの種類を指定しま" "す。" #: ../../library/ast.rst:2631 msgid "Don't parse type comments." msgstr "型コメントをパースしません。" #: ../../library/ast.rst:2635 msgid "Include attributes such as line numbers and column offsets." msgstr "行番号や列オフセットなどの属性を含めます。" #: ../../library/ast.rst:2640 msgid "Indentation of nodes in AST (number of spaces)." msgstr "AST におけるノードのインデント (空白の数) です。" #: ../../library/ast.rst:2644 msgid "" "Python version in the format 3.x (for example, 3.10). Defaults to the " "current version of the interpreter." msgstr "" #: ../../library/ast.rst:2652 msgid "Optimization level for parser. Defaults to no optimization." msgstr "" #: ../../library/ast.rst:2658 msgid "" "Show empty lists and fields that are ``None``. Defaults to not showing empty " "objects." msgstr "" #: ../../library/ast.rst:2664 msgid "" "If :file:`infile` is specified its contents are parsed to AST and dumped to " "stdout. Otherwise, the content is read from stdin." msgstr "" ":file:`infile` を指定するとその内容が AST にパースされて標準出力に出力されま" "す。そうでない場合は標準入力から入力を読み込みます。" #: ../../library/ast.rst:2670 msgid "" "`Green Tree Snakes `_, an external " "documentation resource, has good details on working with Python ASTs." msgstr "" "外部ドキュメント `Green Tree Snakes `_ には Python AST についての詳細が書かれています。" #: ../../library/ast.rst:2673 msgid "" "`ASTTokens `_ " "annotates Python ASTs with the positions of tokens and text in the source " "code that generated them. This is helpful for tools that make source code " "transformations." msgstr "" "`ASTTokens `_ は " "Python AST を、生成元のソースコードのトークン位置やテキストで注解します。これ" "はソースコード変換を行うツールで有用です。 " #: ../../library/ast.rst:2678 msgid "" "`leoAst.py `_ unifies the token-based and parse-tree-based views of python programs " "by inserting two-way links between tokens and ast nodes." msgstr "" #: ../../library/ast.rst:2683 msgid "" "`LibCST `_ parses code as a Concrete Syntax " "Tree that looks like an ast tree and keeps all formatting details. It's " "useful for building automated refactoring (codemod) applications and linters." msgstr "" "`LibCST `_ はコードを ast ツリーに似た構文木 " "(Concrete Syntax Tree) にパースし、かつ全ての書式設定の詳細を保持します。これ" "は自動リファクタリングアプリケーション (codemod) やリンタを作成する際に有用で" "す。" #: ../../library/ast.rst:2688 msgid "" "`Parso `_ is a Python parser that supports " "error recovery and round-trip parsing for different Python versions (in " "multiple Python versions). Parso is also able to list multiple syntax errors " "in your Python file." msgstr "" #: ../../library/ast.rst:59 msgid "? (question mark)" msgstr "? (クエスチョンマーク)" #: ../../library/ast.rst:59 ../../library/ast.rst:60 msgid "in AST grammar" msgstr "" #: ../../library/ast.rst:60 msgid "* (asterisk)" msgstr "* (アスタリスク)"