X Tutup
# 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-02-25 14:44+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" #: ../../howto/enum.rst:5 msgid "Enum HOWTO" msgstr "列挙型 HOWTO" #: ../../howto/enum.rst:11 msgid "" "An :class:`Enum` is a set of symbolic names bound to unique values. They " "are similar to global variables, but they offer a more useful :func:`repr`, " "grouping, type-safety, and a few other features." msgstr "" ":class:`Enum` は、ユニークな値に束縛されたシンボル名の集合です。グローバル変" "数に似ていますが、 :func:`repr` がより便利だったり、グルーピングの機能、型安" "全などいくつかの機能があります。" #: ../../howto/enum.rst:15 msgid "" "They are most useful when you have a variable that can take one of a limited " "selection of values. For example, the days of the week::" msgstr "" "これらは、限られた選択肢の値の一つを取る変数がある場合に便利です。例えば、曜" "日情報があります:" #: ../../howto/enum.rst:18 msgid "" ">>> from enum import Enum\n" ">>> class Weekday(Enum):\n" "... MONDAY = 1\n" "... TUESDAY = 2\n" "... WEDNESDAY = 3\n" "... THURSDAY = 4\n" "... FRIDAY = 5\n" "... SATURDAY = 6\n" "... SUNDAY = 7" msgstr "" #: ../../howto/enum.rst:28 msgid "Or perhaps the RGB primary colors::" msgstr "あるいは、RGB三原色でも構いません::" #: ../../howto/enum.rst:30 msgid "" ">>> from enum import Enum\n" ">>> class Color(Enum):\n" "... RED = 1\n" "... GREEN = 2\n" "... BLUE = 3" msgstr "" #: ../../howto/enum.rst:36 msgid "" "As you can see, creating an :class:`Enum` is as simple as writing a class " "that inherits from :class:`Enum` itself." msgstr "" "ご覧の通り、 :class:`Enum` の作成は :class:`Enum` 自体を継承するクラスを作成" "するのと同じくらい簡単です。" #: ../../howto/enum.rst:39 msgid "Case of Enum Members" msgstr "Enumメンバーは大文字/小文字?" #: ../../howto/enum.rst:41 msgid "" "Because Enums are used to represent constants, and to help avoid issues with " "name clashes between mixin-class methods/attributes and enum names, we " "strongly recommend using UPPER_CASE names for members, and will be using " "that style in our examples." msgstr "" "列挙型は定数を表すために使われるため、また mixin クラスのメソッドや属性との名" "前の衝突の問題を回避するため、メンバには UPPER_CASE の名前を使うことが強く推" "奨されており、例でもこのスタイルを用います。" #: ../../howto/enum.rst:46 msgid "" "Depending on the nature of the enum a member's value may or may not be " "important, but either way that value can be used to get the corresponding " "member::" msgstr "" "列挙型の性質によって、メンバの値は重要な場合とそうでない場合がありますが、い" "ずれの場合でも、その値は対応するメンバを取得するのに使えます::" #: ../../howto/enum.rst:50 msgid "" ">>> Weekday(3)\n" "" msgstr "" #: ../../howto/enum.rst:53 msgid "" "As you can see, the ``repr()`` of a member shows the enum name, the member " "name, and the value. The ``str()`` of a member shows only the enum name and " "member name::" msgstr "" "ご覧の通り、メンバの ``repr()`` は列挙型の名前、メンバの名前、そして値を表示" "します。メンバの ``str()`` は列挙型の名前とメンバの名前のみを表示します。" #: ../../howto/enum.rst:57 msgid "" ">>> print(Weekday.THURSDAY)\n" "Weekday.THURSDAY" msgstr "" #: ../../howto/enum.rst:60 msgid "The *type* of an enumeration member is the enum it belongs to::" msgstr "列挙型のメンバの型はそのメンバの属する列挙型です::" #: ../../howto/enum.rst:62 msgid "" ">>> type(Weekday.MONDAY)\n" "\n" ">>> isinstance(Weekday.FRIDAY, Weekday)\n" "True" msgstr "" #: ../../howto/enum.rst:67 msgid "Enum members have an attribute that contains just their :attr:`!name`::" msgstr "" #: ../../howto/enum.rst:69 msgid "" ">>> print(Weekday.TUESDAY.name)\n" "TUESDAY" msgstr "" #: ../../howto/enum.rst:72 msgid "Likewise, they have an attribute for their :attr:`!value`::" msgstr "" #: ../../howto/enum.rst:75 msgid "" ">>> Weekday.WEDNESDAY.value\n" "3" msgstr "" #: ../../howto/enum.rst:78 msgid "" "Unlike many languages that treat enumerations solely as name/value pairs, " "Python Enums can have behavior added. For example, :class:`datetime.date` " "has two methods for returning the weekday: :meth:`~datetime.date.weekday` " "and :meth:`~datetime.date.isoweekday`. The difference is that one of them " "counts from 0-6 and the other from 1-7. Rather than keep track of that " "ourselves we can add a method to the :class:`!Weekday` enum to extract the " "day from the :class:`~datetime.date` instance and return the matching enum " "member::" msgstr "" #: ../../howto/enum.rst:87 msgid "" "@classmethod\n" "def from_date(cls, date):\n" " return cls(date.isoweekday())" msgstr "" #: ../../howto/enum.rst:91 msgid "The complete :class:`!Weekday` enum now looks like this::" msgstr "" #: ../../howto/enum.rst:93 msgid "" ">>> class Weekday(Enum):\n" "... MONDAY = 1\n" "... TUESDAY = 2\n" "... WEDNESDAY = 3\n" "... THURSDAY = 4\n" "... FRIDAY = 5\n" "... SATURDAY = 6\n" "... SUNDAY = 7\n" "... #\n" "... @classmethod\n" "... def from_date(cls, date):\n" "... return cls(date.isoweekday())" msgstr "" #: ../../howto/enum.rst:106 msgid "Now we can find out what today is! Observe::" msgstr "さて、これで今日が何曜日か調べることができます! 見てみましょう::" #: ../../howto/enum.rst:108 msgid "" ">>> from datetime import date\n" ">>> Weekday.from_date(date.today())\n" "" msgstr "" #: ../../howto/enum.rst:112 msgid "" "Of course, if you're reading this on some other day, you'll see that day " "instead." msgstr "" "もちろん、あなたがこれを読んでいるのが他の曜日ならば、その曜日が代わりに表示" "されます。" #: ../../howto/enum.rst:114 msgid "" "This :class:`!Weekday` enum is great if our variable only needs one day, but " "what if we need several? Maybe we're writing a function to plot chores " "during a week, and don't want to use a :class:`list` -- we could use a " "different type of :class:`Enum`::" msgstr "" #: ../../howto/enum.rst:119 msgid "" ">>> from enum import Flag\n" ">>> class Weekday(Flag):\n" "... MONDAY = 1\n" "... TUESDAY = 2\n" "... WEDNESDAY = 4\n" "... THURSDAY = 8\n" "... FRIDAY = 16\n" "... SATURDAY = 32\n" "... SUNDAY = 64" msgstr "" #: ../../howto/enum.rst:129 msgid "" "We've changed two things: we're inherited from :class:`Flag`, and the values " "are all powers of 2." msgstr "" "ここでは2つの変更が行われています。:class:`Flag` を継承している点と、値がすべ" "て2の累乗である点です。" #: ../../howto/enum.rst:132 msgid "" "Just like the original :class:`!Weekday` enum above, we can have a single " "selection::" msgstr "" #: ../../howto/enum.rst:134 msgid "" ">>> first_week_day = Weekday.MONDAY\n" ">>> first_week_day\n" "" msgstr "" #: ../../howto/enum.rst:138 msgid "" "But :class:`Flag` also allows us to combine several members into a single " "variable::" msgstr "" "ただし、:class:`Flag` は複数のメンバーをひとつの変数にまとめることもできま" "す::" #: ../../howto/enum.rst:141 msgid "" ">>> weekend = Weekday.SATURDAY | Weekday.SUNDAY\n" ">>> weekend\n" "" msgstr "" #: ../../howto/enum.rst:145 msgid "You can even iterate over a :class:`Flag` variable::" msgstr ":class:`Flag` 変数は反復することもできます::" #: ../../howto/enum.rst:147 msgid "" ">>> for day in weekend:\n" "... print(day)\n" "Weekday.SATURDAY\n" "Weekday.SUNDAY" msgstr "" #: ../../howto/enum.rst:152 msgid "Okay, let's get some chores set up::" msgstr "さて、いくつかの家事を設定してみましょう::" #: ../../howto/enum.rst:154 msgid "" ">>> chores_for_ethan = {\n" "... 'feed the cat': Weekday.MONDAY | Weekday.WEDNESDAY | Weekday." "FRIDAY,\n" "... 'do the dishes': Weekday.TUESDAY | Weekday.THURSDAY,\n" "... 'answer SO questions': Weekday.SATURDAY,\n" "... }" msgstr "" #: ../../howto/enum.rst:160 msgid "And a function to display the chores for a given day::" msgstr "指定された日の家事を表示する関数も作成します::" #: ../../howto/enum.rst:162 msgid "" ">>> def show_chores(chores, day):\n" "... for chore, days in chores.items():\n" "... if day in days:\n" "... print(chore)\n" "...\n" ">>> show_chores(chores_for_ethan, Weekday.SATURDAY)\n" "answer SO questions" msgstr "" #: ../../howto/enum.rst:170 msgid "" "In cases where the actual values of the members do not matter, you can save " "yourself some work and use :func:`auto` for the values::" msgstr "" "メンバーの実際の値が重要でない場合は、:func:`auto` を使用することで手間を省く" "ことができます::" #: ../../howto/enum.rst:173 msgid "" ">>> from enum import auto\n" ">>> class Weekday(Flag):\n" "... MONDAY = auto()\n" "... TUESDAY = auto()\n" "... WEDNESDAY = auto()\n" "... THURSDAY = auto()\n" "... FRIDAY = auto()\n" "... SATURDAY = auto()\n" "... SUNDAY = auto()\n" "... WEEKEND = SATURDAY | SUNDAY" msgstr "" #: ../../howto/enum.rst:189 msgid "Programmatic access to enumeration members and their attributes" msgstr "列挙型メンバーおよびそれらの属性へのプログラム的アクセス" #: ../../howto/enum.rst:191 msgid "" "Sometimes it's useful to access members in enumerations programmatically (i." "e. situations where ``Color.RED`` won't do because the exact color is not " "known at program-writing time). ``Enum`` allows such access::" msgstr "" "プログラム的にメンバーに番号でアクセスしたほうが便利な場合があります (すなわ" "ち、プログラムを書いている時点で正確な色がまだわからなく、``Color.RED`` と書" "くのが無理な場合など)。 ``Enum`` ではそのようなアクセスも可能です::" #: ../../howto/enum.rst:195 msgid "" ">>> Color(1)\n" "\n" ">>> Color(3)\n" "" msgstr "" #: ../../howto/enum.rst:200 msgid "If you want to access enum members by *name*, use item access::" msgstr "" "列挙型メンバーに *名前* でアクセスしたい場合はアイテムとしてアクセスできま" "す::" #: ../../howto/enum.rst:202 msgid "" ">>> Color['RED']\n" "\n" ">>> Color['GREEN']\n" "" msgstr "" #: ../../howto/enum.rst:207 msgid "" "If you have an enum member and need its :attr:`!name` or :attr:`!value`::" msgstr "" #: ../../howto/enum.rst:209 msgid "" ">>> member = Color.RED\n" ">>> member.name\n" "'RED'\n" ">>> member.value\n" "1" msgstr "" #: ../../howto/enum.rst:217 msgid "Duplicating enum members and values" msgstr "列挙型メンバーと値の重複" #: ../../howto/enum.rst:219 msgid "Having two enum members with the same name is invalid::" msgstr "同じ名前の列挙型メンバーを複数持つことはできません::" #: ../../howto/enum.rst:221 msgid "" ">>> class Shape(Enum):\n" "... SQUARE = 2\n" "... SQUARE = 3\n" "...\n" "Traceback (most recent call last):\n" "...\n" "TypeError: 'SQUARE' already defined as 2" msgstr "" #: ../../howto/enum.rst:229 msgid "" "However, an enum member can have other names associated with it. Given two " "entries ``A`` and ``B`` with the same value (and ``A`` defined first), ``B`` " "is an alias for the member ``A``. By-value lookup of the value of ``A`` " "will return the member ``A``. By-name lookup of ``A`` will return the " "member ``A``. By-name lookup of ``B`` will also return the member ``A``::" msgstr "" "しかし、列挙型メンバー は、別の名前を持つことができます。 同じ値を持つ " "``A`` と``B`` が与えられた場合(そして ``A`` が先に定義されている場合)、 " "``B`` はメンバー ``A`` に対するエイリアスとなります。 ``A`` の値での検索で" "は、メンバー ``A`` が返されます。 ``A`` の名前での検索ではメンバー ``A`` を" "返します。``B`` の名前での検索も、メンバー ``A`` を返します::" #: ../../howto/enum.rst:235 msgid "" ">>> class Shape(Enum):\n" "... SQUARE = 2\n" "... DIAMOND = 1\n" "... CIRCLE = 3\n" "... ALIAS_FOR_SQUARE = 2\n" "...\n" ">>> Shape.SQUARE\n" "\n" ">>> Shape.ALIAS_FOR_SQUARE\n" "\n" ">>> Shape(2)\n" "" msgstr "" #: ../../howto/enum.rst:250 msgid "" "Attempting to create a member with the same name as an already defined " "attribute (another member, a method, etc.) or attempting to create an " "attribute with the same name as a member is not allowed." msgstr "" "すでに定義されている属性と同じ名前のメンバー (一方がメンバーでもう一方がメ" "ソッド、など) の作成、あるいはメンバーと同じ名前の属性の作成はできません。" #: ../../howto/enum.rst:256 msgid "Ensuring unique enumeration values" msgstr "番号付けの値が一意であることの確認" #: ../../howto/enum.rst:258 msgid "" "By default, enumerations allow multiple names as aliases for the same value. " "When this behavior isn't desired, you can use the :func:`unique` decorator::" msgstr "" "デフォルトでは、列挙型は同じ値のエイリアスとして複数の名前を許容します。この" "振る舞いを望まない場合は、 :func:`unique` デコレータを使用できます::" #: ../../howto/enum.rst:261 msgid "" ">>> from enum import Enum, unique\n" ">>> @unique\n" "... class Mistake(Enum):\n" "... ONE = 1\n" "... TWO = 2\n" "... THREE = 3\n" "... FOUR = 3\n" "...\n" "Traceback (most recent call last):\n" "...\n" "ValueError: duplicate values found in : FOUR -> THREE" msgstr "" #: ../../howto/enum.rst:275 msgid "Using automatic values" msgstr "値の自動設定を使う" #: ../../howto/enum.rst:277 msgid "If the exact value is unimportant you can use :class:`auto`::" msgstr "正確な値が重要でない場合、 :class:`auto` が使えます::" #: ../../howto/enum.rst:279 msgid "" ">>> from enum import Enum, auto\n" ">>> class Color(Enum):\n" "... RED = auto()\n" "... BLUE = auto()\n" "... GREEN = auto()\n" "...\n" ">>> [member.value for member in Color]\n" "[1, 2, 3]" msgstr "" #: ../../howto/enum.rst:288 msgid "" "The values are chosen by :func:`~Enum._generate_next_value_`, which can be " "overridden::" msgstr "" #: ../../howto/enum.rst:291 msgid "" ">>> class AutoName(Enum):\n" "... @staticmethod\n" "... def _generate_next_value_(name, start, count, last_values):\n" "... return name\n" "...\n" ">>> class Ordinal(AutoName):\n" "... NORTH = auto()\n" "... SOUTH = auto()\n" "... EAST = auto()\n" "... WEST = auto()\n" "...\n" ">>> [member.value for member in Ordinal]\n" "['NORTH', 'SOUTH', 'EAST', 'WEST']" msgstr "" #: ../../howto/enum.rst:307 msgid "" "The :meth:`~Enum._generate_next_value_` method must be defined before any " "members." msgstr "" #: ../../howto/enum.rst:310 msgid "Iteration" msgstr "イテレーション" #: ../../howto/enum.rst:312 msgid "Iterating over the members of an enum does not provide the aliases::" msgstr "列挙型のメンバーのイテレートは別名をサポートしていません::" #: ../../howto/enum.rst:314 msgid "" ">>> list(Shape)\n" "[, , ]\n" ">>> list(Weekday)\n" "[, , , , , , ]" msgstr "" #: ../../howto/enum.rst:319 msgid "" "Note that the aliases ``Shape.ALIAS_FOR_SQUARE`` and ``Weekday.WEEKEND`` " "aren't shown." msgstr "" "エイリアスである ``Shape.ALIAS_FOR_SQUARE`` と``Weekday.WEEKEND`` が表示され" "ていないことに注意してください。" #: ../../howto/enum.rst:321 msgid "" "The special attribute ``__members__`` is a read-only ordered mapping of " "names to members. It includes all names defined in the enumeration, " "including the aliases::" msgstr "" "特殊属性 ``__members__`` は読み出し専用で、順序を保持した、対応する名前と列挙" "型メンバーのマッピングです。これには別名も含め、列挙されたすべての名前が入っ" "ています。" #: ../../howto/enum.rst:325 msgid "" ">>> for name, member in Shape.__members__.items():\n" "... name, member\n" "...\n" "('SQUARE', )\n" "('DIAMOND', )\n" "('CIRCLE', )\n" "('ALIAS_FOR_SQUARE', )" msgstr "" #: ../../howto/enum.rst:333 msgid "" "The ``__members__`` attribute can be used for detailed programmatic access " "to the enumeration members. For example, finding all the aliases::" msgstr "" "属性 ``__members__`` は列挙型メンバーへの詳細なアクセスに使用できます。以下は" "すべての別名を探す例です::" #: ../../howto/enum.rst:336 msgid "" ">>> [name for name, member in Shape.__members__.items() if member.name != " "name]\n" "['ALIAS_FOR_SQUARE']" msgstr "" #: ../../howto/enum.rst:341 msgid "" "Aliases for flags include values with multiple flags set, such as ``3``, and " "no flags set, i.e. ``0``." msgstr "" "フラグのエイリアスには、 複数のフラグが設定された値(例えば ``3``)や、 フラ" "グが設定されていない値(例えば ``0``)が含まれます。" #: ../../howto/enum.rst:346 msgid "Comparisons" msgstr "比較" #: ../../howto/enum.rst:348 msgid "Enumeration members are compared by identity::" msgstr "列挙型メンバーは同一性を比較できます::" #: ../../howto/enum.rst:350 msgid "" ">>> Color.RED is Color.RED\n" "True\n" ">>> Color.RED is Color.BLUE\n" "False\n" ">>> Color.RED is not Color.BLUE\n" "True" msgstr "" #: ../../howto/enum.rst:357 msgid "" "Ordered comparisons between enumeration values are *not* supported. Enum " "members are not integers (but see `IntEnum`_ below)::" msgstr "" "列挙型の値の順序の比較はサポートされて *いません*。Enum メンバーは整数ではあ" "りません (`IntEnum`_ を参照してください)::" #: ../../howto/enum.rst:360 msgid "" ">>> Color.RED < Color.BLUE\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: '<' not supported between instances of 'Color' and 'Color'" msgstr "" #: ../../howto/enum.rst:365 msgid "Equality comparisons are defined though::" msgstr "ただし等価の比較は定義されています::" #: ../../howto/enum.rst:367 msgid "" ">>> Color.BLUE == Color.RED\n" "False\n" ">>> Color.BLUE != Color.RED\n" "True\n" ">>> Color.BLUE == Color.BLUE\n" "True" msgstr "" #: ../../howto/enum.rst:374 msgid "" "Comparisons against non-enumeration values will always compare not equal " "(again, :class:`IntEnum` was explicitly designed to behave differently, see " "below)::" msgstr "" "非列挙型の値との比較は常に不等となります (繰り返しになりますが、:class:" "`IntEnum` はこれと異なる挙動になるよう設計されています)::" #: ../../howto/enum.rst:378 msgid "" ">>> Color.BLUE == 2\n" "False" msgstr "" #: ../../howto/enum.rst:383 msgid "" "It is possible to reload modules -- if a reloaded module contains enums, " "they will be recreated, and the new members may not compare identical/equal " "to the original members." msgstr "" "モジュールは再読み込みすることが可能です。再読み込みされたモジュールに列挙型" "が含まれている場合、それらは再作成され、新しいメンバーは元のメンバーと同一で" "ない/等しくない可能性があります。" #: ../../howto/enum.rst:388 msgid "Allowed members and attributes of enumerations" msgstr "列挙型で許されるメンバーと属性" #: ../../howto/enum.rst:390 msgid "" "Most of the examples above use integers for enumeration values. Using " "integers is short and handy (and provided by default by the `Functional " "API`_), but not strictly enforced. In the vast majority of use-cases, one " "doesn't care what the actual value of an enumeration is. But if the value " "*is* important, enumerations can have arbitrary values." msgstr "" "これまでのほとんどの例では、列挙型の値に整数を使用しています。 整数を使うの" "は短くて便利(そして、 `関数 API`_ ではデフォルトで設定される)ですが、これは" "強制されているわけではありません。大半の使用例では、列挙値の実際の値が何であ" "るかは意識しません。しかし、値が重要な場合、列挙型は任意の値を持つことができ" "ます。" #: ../../howto/enum.rst:396 msgid "" "Enumerations are Python classes, and can have methods and special methods as " "usual. If we have this enumeration::" msgstr "" "列挙型は Python のクラスであり、通常どおりメソッドや特殊メソッドを持つことが" "できます::" #: ../../howto/enum.rst:399 msgid "" ">>> class Mood(Enum):\n" "... FUNKY = 1\n" "... HAPPY = 3\n" "...\n" "... def describe(self):\n" "... # self is the member here\n" "... return self.name, self.value\n" "...\n" "... def __str__(self):\n" "... return 'my custom str! {0}'.format(self.value)\n" "...\n" "... @classmethod\n" "... def favorite_mood(cls):\n" "... # cls here is the enumeration\n" "... return cls.HAPPY\n" "..." msgstr "" #: ../../howto/enum.rst:416 msgid "Then::" msgstr "上記の結果が以下のようになります::" #: ../../howto/enum.rst:418 msgid "" ">>> Mood.favorite_mood()\n" "\n" ">>> Mood.HAPPY.describe()\n" "('HAPPY', 3)\n" ">>> str(Mood.FUNKY)\n" "'my custom str! 1'" msgstr "" #: ../../howto/enum.rst:425 msgid "" "The rules for what is allowed are as follows: names that start and end with " "a single underscore are reserved by enum and cannot be used; all other " "attributes defined within an enumeration will become members of this " "enumeration, with the exception of special methods (:meth:`~object." "__str__`, :meth:`~object.__add__`, etc.), descriptors (methods are also " "descriptors), and variable names listed in :attr:`~Enum._ignore_`." msgstr "" #: ../../howto/enum.rst:432 msgid "" "Note: if your enumeration defines :meth:`~object.__new__` and/or :meth:" "`~object.__init__`, any value(s) given to the enum member will be passed " "into those methods. See `Planet`_ for an example." msgstr "" #: ../../howto/enum.rst:438 msgid "" "The :meth:`~object.__new__` method, if defined, is used during creation of " "the Enum members; it is then replaced by Enum's :meth:`~object.__new__` " "which is used after class creation for lookup of existing members. See :ref:" "`new-vs-init` for more details." msgstr "" #: ../../howto/enum.rst:445 msgid "Restricted Enum subclassing" msgstr "Enumのサブクラス化の制限" #: ../../howto/enum.rst:447 msgid "" "A new :class:`Enum` class must have one base enum class, up to one concrete " "data type, and as many :class:`object`-based mixin classes as needed. The " "order of these base classes is::" msgstr "" "新しい :class:`Enum` クラスは、ベースの enum クラスを1つ、具象データ型を1つ、" "複数の :class:`object` ベースのミックスインクラスが許容されます。これらのベー" "スクラスの順序は次の通りです::" #: ../../howto/enum.rst:451 msgid "" "class EnumName([mix-in, ...,] [data-type,] base-enum):\n" " pass" msgstr "" #: ../../howto/enum.rst:454 msgid "" "Also, subclassing an enumeration is allowed only if the enumeration does not " "define any members. So this is forbidden::" msgstr "" "列挙型のサブクラスの作成はその列挙型にメンバーが一つも定義されていない場合の" "み行なえます。従って以下は許されません::" #: ../../howto/enum.rst:457 msgid "" ">>> class MoreColor(Color):\n" "... PINK = 17\n" "...\n" "Traceback (most recent call last):\n" "...\n" "TypeError: cannot extend " msgstr "" #: ../../howto/enum.rst:464 msgid "But this is allowed::" msgstr "以下のような場合は許されます::" #: ../../howto/enum.rst:466 msgid "" ">>> class Foo(Enum):\n" "... def some_behavior(self):\n" "... pass\n" "...\n" ">>> class Bar(Foo):\n" "... HAPPY = 1\n" "... SAD = 2\n" "..." msgstr "" #: ../../howto/enum.rst:475 msgid "" "Allowing subclassing of enums that define members would lead to a violation " "of some important invariants of types and instances. On the other hand, it " "makes sense to allow sharing some common behavior between a group of " "enumerations. (See `OrderedEnum`_ for an example.)" msgstr "" "メンバーが定義された列挙型のサブクラス化を許可すると、いくつかのデータ型およ" "びインスタンスの重要な不変条件の違反を引き起こします。とはいえ、それが許可さ" "れると、列挙型のグループ間での共通の挙動を共有するという利点もあります。 " "(`OrderedEnum`_ の例を参照してください。)" #: ../../howto/enum.rst:484 msgid "Dataclass support" msgstr "データクラスのサポート" #: ../../howto/enum.rst:486 msgid "" "When inheriting from a :class:`~dataclasses.dataclass`, the :meth:`~Enum." "__repr__` omits the inherited class' name. For example::" msgstr "" ":class:`~dataclasses.dataclass` を継承する場合、 :meth:`~Enum.__repr__` は継" "承するクラス名を省略します。 例えば::" #: ../../howto/enum.rst:489 msgid "" ">>> from dataclasses import dataclass, field\n" ">>> @dataclass\n" "... class CreatureDataMixin:\n" "... size: str\n" "... legs: int\n" "... tail: bool = field(repr=False, default=True)\n" "...\n" ">>> class Creature(CreatureDataMixin, Enum):\n" "... BEETLE = 'small', 6\n" "... DOG = 'medium', 4\n" "...\n" ">>> Creature.DOG\n" "" msgstr "" #: ../../howto/enum.rst:503 msgid "" "Use the :func:`~dataclasses.dataclass` argument ``repr=False`` to use the " "standard :func:`repr`." msgstr "" "標準の :func:`repr` を使うには、:func:`~dataclasses.dataclass` の引数 " "``repr=False`` を使用してください。" #: ../../howto/enum.rst:506 msgid "" "Only the dataclass fields are shown in the value area, not the dataclass' " "name." msgstr "" "dataclass のフィールドだけが値の領域に表示され、dataclassの名前は表示されなく" "なりました" #: ../../howto/enum.rst:512 msgid "" "Adding :func:`~dataclasses.dataclass` decorator to :class:`Enum` and its " "subclasses is not supported. It will not raise any errors, but it will " "produce very strange results at runtime, such as members being equal to each " "other::" msgstr "" ":class:`Enum` やそのサブクラスに :func:`~dataclasses.dataclass` デコレータを" "加えることはサポートされていません。そうしてもエラーは送出されませんが、実行" "時にそれぞれのメンバが互いに等しいなど、非常に奇妙な結果が起こります::" #: ../../howto/enum.rst:517 msgid "" ">>> @dataclass # don't do this: it does not make any sense\n" "... class Color(Enum):\n" "... RED = 1\n" "... BLUE = 2\n" "...\n" ">>> Color.RED is Color.BLUE\n" "False\n" ">>> Color.RED == Color.BLUE # problem is here: they should not be equal\n" "True" msgstr "" #: ../../howto/enum.rst:529 msgid "Pickling" msgstr "Pickle 化" #: ../../howto/enum.rst:531 msgid "Enumerations can be pickled and unpickled::" msgstr "列挙型は pickle 化と unpickle 化が行えます::" #: ../../howto/enum.rst:533 msgid "" ">>> from test.test_enum import Fruit\n" ">>> from pickle import dumps, loads\n" ">>> Fruit.TOMATO is loads(dumps(Fruit.TOMATO))\n" "True" msgstr "" #: ../../howto/enum.rst:538 msgid "" "The usual restrictions for pickling apply: picklable enums must be defined " "in the top level of a module, since unpickling requires them to be " "importable from that module." msgstr "" "通常の pickle 化の制限事項が適用されます: pickle 可能な列挙型はモジュールの" "トップレベルで定義されていなくてはならず、unpickle 化はモジュールからインポー" "ト可能でなければなりません。" #: ../../howto/enum.rst:544 msgid "" "With pickle protocol version 4 it is possible to easily pickle enums nested " "in other classes." msgstr "" "pickle プロトコルバージョン 4 では他のクラスで入れ子になった列挙型の pickle " "化も容易です。" #: ../../howto/enum.rst:547 msgid "" "It is possible to modify how enum members are pickled/unpickled by defining :" "meth:`~object.__reduce_ex__` in the enumeration class. The default method " "is by-value, but enums with complicated values may want to use by-name::" msgstr "" #: ../../howto/enum.rst:551 msgid "" ">>> import enum\n" ">>> class MyEnum(enum.Enum):\n" "... __reduce_ex__ = enum.pickle_by_enum_name" msgstr "" #: ../../howto/enum.rst:557 msgid "" "Using by-name for flags is not recommended, as unnamed aliases will not " "unpickle." msgstr "" "フラグに名前による pickle 化を使うことは、名前の無いエイリアスが unpickle 化" "されないため推奨されません。" #: ../../howto/enum.rst:562 msgid "Functional API" msgstr "関数 API" #: ../../howto/enum.rst:564 msgid "" "The :class:`Enum` class is callable, providing the following functional API::" msgstr "" ":class:`Enum` クラスは呼び出し可能で、以下の関数 API を提供しています::" #: ../../howto/enum.rst:566 msgid "" ">>> Animal = Enum('Animal', 'ANT BEE CAT DOG')\n" ">>> Animal\n" "\n" ">>> Animal.ANT\n" "\n" ">>> list(Animal)\n" "[, , , ]" msgstr "" #: ../../howto/enum.rst:574 msgid "" "The semantics of this API resemble :class:`~collections.namedtuple`. The " "first argument of the call to :class:`Enum` is the name of the enumeration." msgstr "" "この API の動作は :class:`~collections.namedtuple` と似ています。:class:" "`Enum` 呼び出しの第 1 引数は列挙型の名前です。" #: ../../howto/enum.rst:577 msgid "" "The second argument is the *source* of enumeration member names. It can be " "a whitespace-separated string of names, a sequence of names, a sequence of 2-" "tuples with key/value pairs, or a mapping (e.g. dictionary) of names to " "values. The last two options enable assigning arbitrary values to " "enumerations; the others auto-assign increasing integers starting with 1 " "(use the ``start`` parameter to specify a different starting value). A new " "class derived from :class:`Enum` is returned. In other words, the above " "assignment to :class:`!Animal` is equivalent to::" msgstr "" #: ../../howto/enum.rst:586 msgid "" ">>> class Animal(Enum):\n" "... ANT = 1\n" "... BEE = 2\n" "... CAT = 3\n" "... DOG = 4\n" "..." msgstr "" #: ../../howto/enum.rst:593 msgid "" "The reason for defaulting to ``1`` as the starting number and not ``0`` is " "that ``0`` is ``False`` in a boolean sense, but by default enum members all " "evaluate to ``True``." msgstr "" "``0`` ではなく``1`` をデフォルトの開始番号とする理由は、``0`` が真偽値として" "は ``False`` であり、デフォルトの列挙メンバーはすべて ``True`` 評価されるよう" "にするためである。" #: ../../howto/enum.rst:597 msgid "" "Pickling enums created with the functional API can be tricky as frame stack " "implementation details are used to try and figure out which module the " "enumeration is being created in (e.g. it will fail if you use a utility " "function in a separate module, and also may not work on IronPython or " "Jython). The solution is to specify the module name explicitly as follows::" msgstr "" "機能 API による Enum の pickle 化は、その列挙型がどのモジュールで作成されたか" "を見つけ出すためにフレームスタックの実装の詳細が使われるので、トリッキーにな" "ることがあります (例えば別のモジュールのユーティリティ関数を使うと失敗します" "し、IronPython や Jython ではうまくいきません)。解決策は、以下のようにモ" "ジュール名を明示的に指定することです::" #: ../../howto/enum.rst:603 msgid ">>> Animal = Enum('Animal', 'ANT BEE CAT DOG', module=__name__)" msgstr "" #: ../../howto/enum.rst:607 msgid "" "If ``module`` is not supplied, and Enum cannot determine what it is, the new " "Enum members will not be unpicklable; to keep errors closer to the source, " "pickling will be disabled." msgstr "" "``module`` が与えられない場合、Enum はそれがなにか決定できないため、新しい " "Enum メンバーは unpickle 化できなくなります; エラーをソースの近いところで発生" "させるため、pickle 化は無効になります。" #: ../../howto/enum.rst:611 msgid "" "The new pickle protocol 4 also, in some circumstances, relies on :attr:" "`~type.__qualname__` being set to the location where pickle will be able to " "find the class. For example, if the class was made available in class " "SomeData in the global scope::" msgstr "" #: ../../howto/enum.rst:616 msgid "" ">>> Animal = Enum('Animal', 'ANT BEE CAT DOG', qualname='SomeData.Animal')" msgstr "" #: ../../howto/enum.rst:618 msgid "The complete signature is::" msgstr "完全な構文は以下のようになります::" #: ../../howto/enum.rst:620 msgid "" "Enum(\n" " value='NewEnumName',\n" " names=<...>,\n" " *,\n" " module='...',\n" " qualname='...',\n" " type=,\n" " start=1,\n" " )" msgstr "" #: ../../howto/enum.rst:630 msgid "*value*: What the new enum class will record as its name." msgstr "" #: ../../howto/enum.rst:632 msgid "" "*names*: The enum members. This can be a whitespace- or comma-separated " "string (values will start at 1 unless otherwise specified)::" msgstr "" "*names*: enumのメンバー。 空白またはカンマで区切られた文字列 (値は特に指定が" "ない限り1から始まります)::" #: ../../howto/enum.rst:635 msgid "'RED GREEN BLUE' | 'RED,GREEN,BLUE' | 'RED, GREEN, BLUE'" msgstr "" #: ../../howto/enum.rst:637 msgid "or an iterator of names::" msgstr "または名前のイテレータで指定もできます::" #: ../../howto/enum.rst:639 msgid "['RED', 'GREEN', 'BLUE']" msgstr "" #: ../../howto/enum.rst:641 msgid "or an iterator of (name, value) pairs::" msgstr "または (名前, 値) のペアのイテレータでも指定できます::" #: ../../howto/enum.rst:643 msgid "[('CYAN', 4), ('MAGENTA', 5), ('YELLOW', 6)]" msgstr "" #: ../../howto/enum.rst:645 msgid "or a mapping::" msgstr "またはマッピングでも指定できます::" #: ../../howto/enum.rst:647 msgid "{'CHARTREUSE': 7, 'SEA_GREEN': 11, 'ROSEMARY': 42}" msgstr "" #: ../../howto/enum.rst:649 msgid "*module*: name of module where new enum class can be found." msgstr "*module*: 新しい enum クラスが属するモジュールの名前です。" #: ../../howto/enum.rst:651 msgid "*qualname*: where in module new enum class can be found." msgstr "*qualname*: 新しい enum クラスが属するモジュールの場所です。" #: ../../howto/enum.rst:653 msgid "*type*: type to mix in to new enum class." msgstr "*type*: 新しい列挙型クラスにミックスインする型。" #: ../../howto/enum.rst:655 msgid "*start*: number to start counting at if only names are passed in." msgstr "*start*:名前だけ渡された場合にカウントを開始する番号。" #: ../../howto/enum.rst:657 msgid "The *start* parameter was added." msgstr "*start* 引数が追加されました。" #: ../../howto/enum.rst:662 msgid "Derived Enumerations" msgstr "派生列挙型" #: ../../howto/enum.rst:665 msgid "IntEnum" msgstr "IntEnum" #: ../../howto/enum.rst:667 msgid "" "The first variation of :class:`Enum` that is provided is also a subclass of :" "class:`int`. Members of an :class:`IntEnum` can be compared to integers; by " "extension, integer enumerations of different types can also be compared to " "each other::" msgstr "" "提供されている 1 つ目の :class:`Enum` の派生型であり、 :class:`int` のサブク" "ラスでもあります。\n" ":class:`IntEnum` のメンバーは整数と比較できます;\n" "さらに言うと、異なる整数列挙型どうしでも比較できます::" #: ../../howto/enum.rst:672 msgid "" ">>> from enum import IntEnum\n" ">>> class Shape(IntEnum):\n" "... CIRCLE = 1\n" "... SQUARE = 2\n" "...\n" ">>> class Request(IntEnum):\n" "... POST = 1\n" "... GET = 2\n" "...\n" ">>> Shape == 1\n" "False\n" ">>> Shape.CIRCLE == 1\n" "True\n" ">>> Shape.CIRCLE == Request.POST\n" "True" msgstr "" #: ../../howto/enum.rst:688 msgid "" "However, they still can't be compared to standard :class:`Enum` " "enumerations::" msgstr "ただし、これらも標準の :class:`Enum` 列挙型とは比較できません::" #: ../../howto/enum.rst:690 msgid "" ">>> class Shape(IntEnum):\n" "... CIRCLE = 1\n" "... SQUARE = 2\n" "...\n" ">>> class Color(Enum):\n" "... RED = 1\n" "... GREEN = 2\n" "...\n" ">>> Shape.CIRCLE == Color.RED\n" "False" msgstr "" #: ../../howto/enum.rst:701 msgid "" ":class:`IntEnum` values behave like integers in other ways you'd expect::" msgstr ":class:`IntEnum` の値は他の用途では整数のように振る舞います::" #: ../../howto/enum.rst:703 msgid "" ">>> int(Shape.CIRCLE)\n" "1\n" ">>> ['a', 'b', 'c'][Shape.CIRCLE]\n" "'b'\n" ">>> [i for i in range(Shape.SQUARE)]\n" "[0, 1]" msgstr "" #: ../../howto/enum.rst:712 msgid "StrEnum" msgstr "StrEnum" #: ../../howto/enum.rst:714 msgid "" "The second variation of :class:`Enum` that is provided is also a subclass " "of :class:`str`. Members of a :class:`StrEnum` can be compared to strings; " "by extension, string enumerations of different types can also be compared to " "each other." msgstr "" "提供されている2つ目の :class:`Enum` の派生型もまた、 :class:`str` のサブクラ" "スでもあります。:class:`StrEnum` のメンバーは、文字列と比較できます; さらに言" "うと、異なる文字列列挙型どうしでも比較できます。" #: ../../howto/enum.rst:723 msgid "IntFlag" msgstr "IntFlag" #: ../../howto/enum.rst:725 msgid "" "The next variation of :class:`Enum` provided, :class:`IntFlag`, is also " "based on :class:`int`. The difference being :class:`IntFlag` members can be " "combined using the bitwise operators (&, \\|, ^, ~) and the result is still " "an :class:`IntFlag` member, if possible. Like :class:`IntEnum`, :class:" "`IntFlag` members are also integers and can be used wherever an :class:`int` " "is used." msgstr "" "次の :class:`Enum` の派生型 :class:`IntFlag` も、:class:`int` を基底クラスと" "しています。\n" "違いは、 :class:`IntFlag` のメンバーをビット演算子 (&, \\|, ^, ~) を使っ" "て組み合わせられ、その結果も :class:`IntFlag` メンバーになることです。 :" "class:`IntEnum` と同様、:class:`IntFlag` のメンバーも整数であり、:class:" "`int` が使用されるところであればどこでも使えます。" #: ../../howto/enum.rst:733 msgid "" "Any operation on an :class:`IntFlag` member besides the bit-wise operations " "will lose the :class:`IntFlag` membership." msgstr "" ":class:`IntFlag` メンバーに対してビット演算以外のどんな演算をしても、その結果" "は :class:`IntFlag` メンバーではなくなります。" #: ../../howto/enum.rst:736 msgid "" "Bit-wise operations that result in invalid :class:`IntFlag` values will lose " "the :class:`IntFlag` membership. See :class:`FlagBoundary` for details." msgstr "" "ビット単位演算の結果が :class:`IntFlag` として不正な値な値の場合、値は :" "class:`IntFlag` メンバーではなくなります。 詳しくは :class:`FlagBoundary` を" "参照してください。" #: ../../howto/enum.rst:743 msgid "Sample :class:`IntFlag` class::" msgstr ":class:`IntFlag` クラスの例::" #: ../../howto/enum.rst:745 msgid "" ">>> from enum import IntFlag\n" ">>> class Perm(IntFlag):\n" "... R = 4\n" "... W = 2\n" "... X = 1\n" "...\n" ">>> Perm.R | Perm.W\n" "\n" ">>> Perm.R + Perm.W\n" "6\n" ">>> RW = Perm.R | Perm.W\n" ">>> Perm.R in RW\n" "True" msgstr "" #: ../../howto/enum.rst:759 msgid "It is also possible to name the combinations::" msgstr "組み合わせにも名前を付けられます::" #: ../../howto/enum.rst:761 msgid "" ">>> class Perm(IntFlag):\n" "... R = 4\n" "... W = 2\n" "... X = 1\n" "... RWX = 7\n" "...\n" ">>> Perm.RWX\n" "\n" ">>> ~Perm.RWX\n" "\n" ">>> Perm(7)\n" "" msgstr "" #: ../../howto/enum.rst:776 msgid "" "Named combinations are considered aliases. Aliases do not show up during " "iteration, but can be returned from by-value lookups." msgstr "" "組み合わせに名前をつけたものはエイリアスとみなされます。エイリアスはイテレー" "ション中には表示されませんが、値による検索では返却されます。" #: ../../howto/enum.rst:781 msgid "" "Another important difference between :class:`IntFlag` and :class:`Enum` is " "that if no flags are set (the value is 0), its boolean evaluation is :data:" "`False`::" msgstr "" ":class:`IntFlag` と :class:`Enum` のもう 1 つの重要な違いは、フラグが設定され" "ていない (値が0である) 場合、その真偽値としての評価は :data:`False` になるこ" "とです::" #: ../../howto/enum.rst:784 msgid "" ">>> Perm.R & Perm.X\n" "\n" ">>> bool(Perm.R & Perm.X)\n" "False" msgstr "" #: ../../howto/enum.rst:789 msgid "" "Because :class:`IntFlag` members are also subclasses of :class:`int` they " "can be combined with them (but may lose :class:`IntFlag` membership::" msgstr "" ":class:`IntFlag` メンバーも :class:`int` のサブクラスであるため、それらと組み" "合わせることができます(ただし、 :class:`IntFlag` 型ではなくなる可能性があり" "ます)::" #: ../../howto/enum.rst:792 msgid "" ">>> Perm.X | 4\n" "\n" "\n" ">>> Perm.X + 8\n" "9" msgstr "" #: ../../howto/enum.rst:800 msgid "" "The negation operator, ``~``, always returns an :class:`IntFlag` member with " "a positive value::" msgstr "" "否定の演算子 ``~`` は、常に正の値を持つ :class:`IntFlag` メンバー を返す::" #: ../../howto/enum.rst:803 msgid "" ">>> (~Perm.X).value == (Perm.R|Perm.W).value == 6\n" "True" msgstr "" #: ../../howto/enum.rst:806 msgid ":class:`IntFlag` members can also be iterated over::" msgstr ":class:`IntFlag` メンバーは反復処理することもできます::" #: ../../howto/enum.rst:808 msgid "" ">>> list(RW)\n" "[, ]" msgstr "" #: ../../howto/enum.rst:815 msgid "Flag" msgstr "Flag" #: ../../howto/enum.rst:817 msgid "" "The last variation is :class:`Flag`. Like :class:`IntFlag`, :class:`Flag` " "members can be combined using the bitwise operators (&, \\|, ^, ~). Unlike :" "class:`IntFlag`, they cannot be combined with, nor compared against, any " "other :class:`Flag` enumeration, nor :class:`int`. While it is possible to " "specify the values directly it is recommended to use :class:`auto` as the " "value and let :class:`Flag` select an appropriate value." msgstr "" "最後の派生型は :class:`Flag` です。\n" ":class:`IntFlag` と同様に、 :class:`Flag` メンバーもビット演算子 (&, \\|, ^, " "~) を使って組み合わせられます。\n" "しかし :class:`IntFlag` とは違い、他のどの :class:`Flag` 列挙型とも :class:" "`int` とも組み合わせたり、比較したりできません。\n" "値を直接指定することも可能ですが、値として :class:`auto` を使い、 :class:" "`Flag` に適切な値を選ばせることが推奨されています。" #: ../../howto/enum.rst:826 msgid "" "Like :class:`IntFlag`, if a combination of :class:`Flag` members results in " "no flags being set, the boolean evaluation is :data:`False`::" msgstr "" ":class:`IntFlag` と同様に、 :class:`Flag` メンバーの組み合わせがどのフラグも" "設定されていない状態になった場合、その真偽値としての評価は :data:`False` とな" "ります::" #: ../../howto/enum.rst:829 msgid "" ">>> from enum import Flag, auto\n" ">>> class Color(Flag):\n" "... RED = auto()\n" "... BLUE = auto()\n" "... GREEN = auto()\n" "...\n" ">>> Color.RED & Color.GREEN\n" "\n" ">>> bool(Color.RED & Color.GREEN)\n" "False" msgstr "" #: ../../howto/enum.rst:840 msgid "" "Individual flags should have values that are powers of two (1, 2, 4, " "8, ...), while combinations of flags will not::" msgstr "" "個別のフラグは 2 のべき乗 (1, 2, 4, 8, ...) の値を持つべきですが、フラグの組" "み合わせはそうはなりません::" #: ../../howto/enum.rst:843 msgid "" ">>> class Color(Flag):\n" "... RED = auto()\n" "... BLUE = auto()\n" "... GREEN = auto()\n" "... WHITE = RED | BLUE | GREEN\n" "...\n" ">>> Color.WHITE\n" "" msgstr "" #: ../../howto/enum.rst:852 msgid "" "Giving a name to the \"no flags set\" condition does not change its boolean " "value::" msgstr "" "\"フラグが設定されていない\" 状態に名前を付けても、その真偽値は変わりません::" #: ../../howto/enum.rst:855 msgid "" ">>> class Color(Flag):\n" "... BLACK = 0\n" "... RED = auto()\n" "... BLUE = auto()\n" "... GREEN = auto()\n" "...\n" ">>> Color.BLACK\n" "\n" ">>> bool(Color.BLACK)\n" "False" msgstr "" #: ../../howto/enum.rst:866 msgid ":class:`Flag` members can also be iterated over::" msgstr ":class:`Flag` メンバーは反復処理することもできます::" #: ../../howto/enum.rst:868 msgid "" ">>> purple = Color.RED | Color.BLUE\n" ">>> list(purple)\n" "[, ]" msgstr "" #: ../../howto/enum.rst:876 msgid "" "For the majority of new code, :class:`Enum` and :class:`Flag` are strongly " "recommended, since :class:`IntEnum` and :class:`IntFlag` break some semantic " "promises of an enumeration (by being comparable to integers, and thus by " "transitivity to other unrelated enumerations). :class:`IntEnum` and :class:" "`IntFlag` should be used only in cases where :class:`Enum` and :class:`Flag` " "will not do; for example, when integer constants are replaced with " "enumerations, or for interoperability with other systems." msgstr "" "ほとんどの新しいコードでは、 :class:`Enum` と :class:`Flag` が強く推奨されま" "す。\n" "というのは、 :class:`IntEnum` と :class:`IntFlag` は (整数と比較でき、従って" "推移的に他の無関係な列挙型と比較できてしまうことにより) 列挙型の意味論的な約" "束に反するからです。\n" ":class:`IntEnum` と :class:`IntFlag` は、 :class:`Enum` や :class:`Flag` では" "上手くいかない場合のみに使うべきです;\n" "例えば、整数定数を列挙型で置き換えるときや、他のシステムとの相互運用性を持た" "せたいときです。" #: ../../howto/enum.rst:886 msgid "Others" msgstr "その他" #: ../../howto/enum.rst:888 msgid "" "While :class:`IntEnum` is part of the :mod:`enum` module, it would be very " "simple to implement independently::" msgstr "" ":class:`IntEnum` は :mod:`enum` モジュールの一部ですが、単独での実装もとても" "簡単に行なえます::" #: ../../howto/enum.rst:891 msgid "" "class IntEnum(int, ReprEnum): # or Enum instead of ReprEnum\n" " pass" msgstr "" #: ../../howto/enum.rst:894 msgid "" "This demonstrates how similar derived enumerations can be defined; for " "example a :class:`!FloatEnum` that mixes in :class:`float` instead of :class:" "`int`." msgstr "" #: ../../howto/enum.rst:897 msgid "Some rules:" msgstr "いくつかのルール:" #: ../../howto/enum.rst:899 msgid "" "When subclassing :class:`Enum`, mix-in types must appear before the :class:" "`Enum` class itself in the sequence of bases, as in the :class:`IntEnum` " "example above." msgstr "" ":class:`Enum` のサブクラスを作成するとき、複合させるデータ型は、基底クラスの" "並びで :class:`Enum` クラス自身より先に記述しなければなりません (上記 :class:" "`IntEnum` の例を参照)。" #: ../../howto/enum.rst:902 msgid "" "Mix-in types must be subclassable. For example, :class:`bool` and :class:" "`range` are not subclassable and will throw an error during Enum creation if " "used as the mix-in type." msgstr "" "複合させる型はサブクラス化可能でなければいけません。例えば、 :class:`bool` " "と :class:`range` はサブクラス化できないため、複合させるとEnum作成時にエラー" "が発生します。" #: ../../howto/enum.rst:905 msgid "" "While :class:`Enum` can have members of any type, once you mix in an " "additional type, all the members must have values of that type, e.g. :class:" "`int` above. This restriction does not apply to mix-ins which only add " "methods and don't specify another type." msgstr "" ":class:`Enum` のメンバーはどんなデータ型でも構いませんが、追加のデータ型 (例" "えば、上の例の :class:`int`) と複合させてしまうと、すべてのメンバーの値はその" "データ型でなければならなくなります。この制限は、メソッドの追加するだけの、他" "のデータ型を指定しない複合には適用されません。" #: ../../howto/enum.rst:909 msgid "" "When another data type is mixed in, the :attr:`~Enum.value` attribute is " "*not the same* as the enum member itself, although it is equivalent and will " "compare equal." msgstr "" #: ../../howto/enum.rst:912 msgid "" "A ``data type`` is a mixin that defines :meth:`~object.__new__`, or a :class:" "`~dataclasses.dataclass`" msgstr "" #: ../../howto/enum.rst:914 msgid "" "%-style formatting: ``%s`` and ``%r`` call the :class:`Enum` class's :meth:" "`~object.__str__` and :meth:`~object.__repr__` respectively; other codes " "(such as ``%i`` or ``%h`` for IntEnum) treat the enum member as its mixed-in " "type." msgstr "" #: ../../howto/enum.rst:917 msgid "" ":ref:`Formatted string literals `, :meth:`str.format`, and :func:" "`format` will use the enum's :meth:`~object.__str__` method." msgstr "" #: ../../howto/enum.rst:922 msgid "" "Because :class:`IntEnum`, :class:`IntFlag`, and :class:`StrEnum` are " "designed to be drop-in replacements for existing constants, their :meth:" "`~object.__str__` method has been reset to their data types' :meth:`~object." "__str__` method." msgstr "" #: ../../howto/enum.rst:930 msgid "When to use :meth:`~object.__new__` vs. :meth:`~object.__init__`" msgstr "" #: ../../howto/enum.rst:932 msgid "" ":meth:`~object.__new__` must be used whenever you want to customize the " "actual value of the :class:`Enum` member. Any other modifications may go in " "either :meth:`~object.__new__` or :meth:`~object.__init__`, with :meth:" "`~object.__init__` being preferred." msgstr "" #: ../../howto/enum.rst:936 msgid "" "For example, if you want to pass several items to the constructor, but only " "want one of them to be the value::" msgstr "" "例えば、複数の値をコンストラクタに渡すが、その中の1つだけを値として使いたい場" "合は次のようにします:" #: ../../howto/enum.rst:939 msgid "" ">>> class Coordinate(bytes, Enum):\n" "... \"\"\"\n" "... Coordinate with binary codes that can be indexed by the int code.\n" "... \"\"\"\n" "... def __new__(cls, value, label, unit):\n" "... obj = bytes.__new__(cls, [value])\n" "... obj._value_ = value\n" "... obj.label = label\n" "... obj.unit = unit\n" "... return obj\n" "... PX = (0, 'P.X', 'km')\n" "... PY = (1, 'P.Y', 'km')\n" "... VX = (2, 'V.X', 'km/s')\n" "... VY = (3, 'V.Y', 'km/s')\n" "...\n" "\n" ">>> print(Coordinate['PY'])\n" "Coordinate.PY\n" "\n" ">>> print(Coordinate(3))\n" "Coordinate.VY" msgstr "" #: ../../howto/enum.rst:963 msgid "" "*Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the " "one that is found; instead, use the data type directly." msgstr "" #: ../../howto/enum.rst:968 msgid "Finer Points" msgstr "細かい点" #: ../../howto/enum.rst:971 msgid "Supported ``__dunder__`` names" msgstr "``__dunder__`` 名のサポート" #: ../../howto/enum.rst:973 msgid "" ":attr:`~enum.EnumType.__members__` is a read-only ordered mapping of " "``member_name``:``member`` items. It is only available on the class." msgstr "" #: ../../howto/enum.rst:976 msgid "" ":meth:`~object.__new__`, if specified, must create and return the enum " "members; it is also a very good idea to set the member's :attr:`~Enum." "_value_` appropriately. Once all the members are created it is no longer " "used." msgstr "" #: ../../howto/enum.rst:982 msgid "Supported ``_sunder_`` names" msgstr "``_sunder_`` 名のサポート" #: ../../howto/enum.rst:984 msgid ":attr:`~Enum._name_` -- name of the member" msgstr ":attr:`~Enum._name_` -- メンバー名" #: ../../howto/enum.rst:985 msgid ":attr:`~Enum._value_` -- value of the member; can be set in ``__new__``" msgstr ":attr:`~Enum._value_` -- メンバーの値; ``__new__`` で設定できます" #: ../../howto/enum.rst:986 msgid "" ":meth:`~Enum._missing_` -- a lookup function used when a value is not found; " "may be overridden" msgstr "" ":meth:`~Enum._missing_` -- 値が見付からなかったときに使われる検索関数; オー" "バーライドされていることがあります" #: ../../howto/enum.rst:988 msgid "" ":attr:`~Enum._ignore_` -- a list of names, either as a :class:`list` or a :" "class:`str`, that will not be transformed into members, and will be removed " "from the final class" msgstr "" ":attr:`~Enum._ignore_` -- 名前のリストで、 :class:`list` もしくは :class:" "`str` です。この名前の要素はメンバーへの変換が行われず、最終的なクラスから削" "除されます。" #: ../../howto/enum.rst:991 msgid "" ":meth:`~Enum._generate_next_value_` -- used to get an appropriate value for " "an enum member; may be overridden" msgstr "" ":meth:`~Enum._generate_next_value_` -- 列挙型のメンバーの適切な値を取得するの" "に使われます。オーバーライドされます。" #: ../../howto/enum.rst:993 msgid "" ":meth:`~Enum._add_alias_` -- adds a new name as an alias to an existing " "member." msgstr "" #: ../../howto/enum.rst:995 msgid "" ":meth:`~Enum._add_value_alias_` -- adds a new value as an alias to an " "existing member. See `MultiValueEnum`_ for an example." msgstr "" #: ../../howto/enum.rst:1000 msgid "" "For standard :class:`Enum` classes the next value chosen is the highest " "value seen incremented by one." msgstr "" "標準の :class:`Enum` クラスの場合、次の値として選択されるのは、定義された最大" "の値に1を加えたものです。" #: ../../howto/enum.rst:1003 msgid "" "For :class:`Flag` classes the next value chosen will be the next highest " "power-of-two." msgstr "" ":class:`Flag` クラスでは、次に選ばれる値は、次の最大の2のべき乗となります。" #: ../../howto/enum.rst:1006 msgid "" "Prior versions would use the last seen value instead of the highest value." msgstr "" "以前のバージョンでは最大の値ではなく最後に定義された値を使っていました。" #: ../../howto/enum.rst:1009 msgid "``_missing_``, ``_order_``, ``_generate_next_value_``" msgstr "``_missing_``, ``_order_``, ``_generate_next_value_``" #: ../../howto/enum.rst:1010 msgid "``_ignore_``" msgstr "``_ignore_``" #: ../../howto/enum.rst:1011 msgid "``_add_alias_``, ``_add_value_alias_``" msgstr "" #: ../../howto/enum.rst:1013 msgid "" "To help keep Python 2 / Python 3 code in sync an :attr:`~Enum._order_` " "attribute can be provided. It will be checked against the actual order of " "the enumeration and raise an error if the two do not match::" msgstr "" #: ../../howto/enum.rst:1017 msgid "" ">>> class Color(Enum):\n" "... _order_ = 'RED GREEN BLUE'\n" "... RED = 1\n" "... BLUE = 3\n" "... GREEN = 2\n" "...\n" "Traceback (most recent call last):\n" "...\n" "TypeError: member order does not match _order_:\n" " ['RED', 'BLUE', 'GREEN']\n" " ['RED', 'GREEN', 'BLUE']" msgstr "" #: ../../howto/enum.rst:1031 msgid "" "In Python 2 code the :attr:`~Enum._order_` attribute is necessary as " "definition order is lost before it can be recorded." msgstr "" #: ../../howto/enum.rst:1036 msgid "_Private__names" msgstr "_Private__names" #: ../../howto/enum.rst:1038 msgid "" ":ref:`Private names ` are not converted to enum " "members, but remain normal attributes." msgstr "" ":ref:`Private names` は列挙型メンバーには変換されず、" "通常の属性となります。" #: ../../howto/enum.rst:1045 msgid "``Enum`` member type" msgstr "``Enum`` メンバー型" #: ../../howto/enum.rst:1047 msgid "" "Enum members are instances of their enum class, and are normally accessed as " "``EnumClass.member``. In certain situations, such as writing custom enum " "behavior, being able to access one member directly from another is useful, " "and is supported; however, in order to avoid name clashes between member " "names and attributes/methods from mixed-in classes, upper-case names are " "strongly recommended." msgstr "" "列挙型メンバーはその列挙型クラスのインスタンスであり、通常は ``EnumClass." "member`` としてアクセスされます。 振る舞い メンバー しかし、メンバー の名前" "と、属性/methodsが混在しているクラスとの名前の衝突を避けるために、大文字の名" "前を使うことを強く推奨します。" #: ../../howto/enum.rst:1058 msgid "Creating members that are mixed with other data types" msgstr "" #: ../../howto/enum.rst:1060 msgid "" "When subclassing other data types, such as :class:`int` or :class:`str`, " "with an :class:`Enum`, all values after the ``=`` are passed to that data " "type's constructor. For example::" msgstr "" " :class:`int` や:class:`str` などの他のデータ型と :class:`Enum` のサブクラス" "では、 ``=`` 以降の値はすべて、そのデータ型のコンストラクタに渡される。 例え" "ば::" #: ../../howto/enum.rst:1064 msgid "" ">>> class MyEnum(IntEnum): # help(int) -> int(x, base=10) -> integer\n" "... example = '11', 16 # so x='11' and base=16\n" "...\n" ">>> MyEnum.example.value # and hex(11) is...\n" "17" msgstr "" #: ../../howto/enum.rst:1072 msgid "Boolean value of ``Enum`` classes and members" msgstr "``Enum`` クラスとメンバーの真偽値" #: ../../howto/enum.rst:1074 msgid "" "Enum classes that are mixed with non-:class:`Enum` types (such as :class:" "`int`, :class:`str`, etc.) are evaluated according to the mixed-in type's " "rules; otherwise, all members evaluate as :data:`True`. To make your own " "enum's boolean evaluation depend on the member's value add the following to " "your class::" msgstr "" "(:class:`int`, :class:`str` などのような) 非 :class:`Enum` 型と複合させた " "enum クラスは、その複合された型の規則に従って評価されます;\n" "そうでない場合は、全てのメンバーは :data:`True` と評価されます。\n" "メンバーの値に依存する独自の enum の真偽値評価を行うには、クラスに次のコード" "を追加してください::" #: ../../howto/enum.rst:1080 msgid "" "def __bool__(self):\n" " return bool(self.value)" msgstr "" #: ../../howto/enum.rst:1083 msgid "Plain :class:`Enum` classes always evaluate as :data:`True`." msgstr "プレーンな :class:`Enum` クラスは :data:`True` として評価されます。" #: ../../howto/enum.rst:1087 msgid "``Enum`` classes with methods" msgstr "メソッド付きの ``Enum`` クラス" #: ../../howto/enum.rst:1089 msgid "" "If you give your enum subclass extra methods, like the `Planet`_ class " "below, those methods will show up in a :func:`dir` of the member, but not of " "the class::" msgstr "" "enum サブクラスに追加のメソッドを与えた場合、後述の `Planet`_ クラスのよう" "に、そのメソッドはメンバーの :func:`dir` に表示されますが、クラスの :func:" "`dir` には表示されません::" #: ../../howto/enum.rst:1093 msgid "" ">>> dir(Planet)\n" "['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', " "'VENUS', '__class__', '__doc__', '__members__', '__module__']\n" ">>> dir(Planet.EARTH)\n" "['__class__', '__doc__', '__module__', 'mass', 'name', 'radius', " "'surface_gravity', 'value']" msgstr "" #: ../../howto/enum.rst:1100 msgid "Combining members of ``Flag``" msgstr "``Flag`` のメンバーの組み合わせ" #: ../../howto/enum.rst:1102 msgid "" "Iterating over a combination of :class:`Flag` members will only return the " "members that are comprised of a single bit::" msgstr "" #: ../../howto/enum.rst:1105 msgid "" ">>> class Color(Flag):\n" "... RED = auto()\n" "... GREEN = auto()\n" "... BLUE = auto()\n" "... MAGENTA = RED | BLUE\n" "... YELLOW = RED | GREEN\n" "... CYAN = GREEN | BLUE\n" "...\n" ">>> Color(3) # named combination\n" "\n" ">>> Color(7) # not named combination\n" "" msgstr "" #: ../../howto/enum.rst:1120 msgid "``Flag`` and ``IntFlag`` minutia" msgstr "" #: ../../howto/enum.rst:1122 msgid "Using the following snippet for our examples::" msgstr "例として以下のスニペットを使用します::" #: ../../howto/enum.rst:1124 msgid "" ">>> class Color(IntFlag):\n" "... BLACK = 0\n" "... RED = 1\n" "... GREEN = 2\n" "... BLUE = 4\n" "... PURPLE = RED | BLUE\n" "... WHITE = RED | GREEN | BLUE\n" "..." msgstr "" #: ../../howto/enum.rst:1133 msgid "the following are true:" msgstr "" #: ../../howto/enum.rst:1135 msgid "single-bit flags are canonical" msgstr "単一ビットのフラグは正規形です" #: ../../howto/enum.rst:1136 msgid "multi-bit and zero-bit flags are aliases" msgstr "複数ビットや0ビットのフラグはエイリアスです" #: ../../howto/enum.rst:1137 msgid "only canonical flags are returned during iteration::" msgstr "反復処理では正規形のフラグのみ返却されます::" #: ../../howto/enum.rst:1139 msgid "" ">>> list(Color.WHITE)\n" "[, , ]" msgstr "" #: ../../howto/enum.rst:1142 msgid "" "negating a flag or flag set returns a new flag/flag set with the " "corresponding positive integer value::" msgstr "" #: ../../howto/enum.rst:1145 msgid "" ">>> Color.BLUE\n" "\n" "\n" ">>> ~Color.BLUE\n" "" msgstr "" #: ../../howto/enum.rst:1151 msgid "names of pseudo-flags are constructed from their members' names::" msgstr "名前のないフラグについては、そのメンバーの名前から名前が生成されます::" #: ../../howto/enum.rst:1153 msgid "" ">>> (Color.RED | Color.GREEN).name\n" "'RED|GREEN'\n" "\n" ">>> class Perm(IntFlag):\n" "... R = 4\n" "... W = 2\n" "... X = 1\n" "...\n" ">>> (Perm.R & Perm.W).name is None # effectively Perm(0)\n" "True" msgstr "" #: ../../howto/enum.rst:1164 msgid "multi-bit flags, aka aliases, can be returned from operations::" msgstr "" #: ../../howto/enum.rst:1166 msgid "" ">>> Color.RED | Color.BLUE\n" "\n" "\n" ">>> Color(7) # or Color(-1)\n" "\n" "\n" ">>> Color(0)\n" "" msgstr "" #: ../../howto/enum.rst:1175 msgid "" "membership / containment checking: zero-valued flags are always considered " "to be contained::" msgstr "" "メンバーシップ/包含 のチェックでは、値が0のフラグは常に含まれるものとして扱わ" "れます::" #: ../../howto/enum.rst:1178 msgid "" ">>> Color.BLACK in Color.WHITE\n" "True" msgstr "" #: ../../howto/enum.rst:1181 msgid "" "otherwise, only if all bits of one flag are in the other flag will True be " "returned::" msgstr "" "それ以外では、一方のフラグの全ビットが他方のフラグに含まれる場合のみ、Trueが" "返されます::" #: ../../howto/enum.rst:1184 msgid "" ">>> Color.PURPLE in Color.WHITE\n" "True\n" "\n" ">>> Color.GREEN in Color.PURPLE\n" "False" msgstr "" #: ../../howto/enum.rst:1190 msgid "" "There is a new boundary mechanism that controls how out-of-range / invalid " "bits are handled: ``STRICT``, ``CONFORM``, ``EJECT``, and ``KEEP``:" msgstr "" #: ../../howto/enum.rst:1193 msgid "STRICT --> raises an exception when presented with invalid values" msgstr "STRICT --> 無効な値が指定された場合に例外を発生させる" #: ../../howto/enum.rst:1194 msgid "CONFORM --> discards any invalid bits" msgstr "CONFORM --> 無効なビットを破棄する" #: ../../howto/enum.rst:1195 msgid "EJECT --> lose Flag status and become a normal int with the given value" msgstr "" "EJECT --> フラグのステータスを失い、指定された値を持つ通常の int となります。" #: ../../howto/enum.rst:1196 msgid "KEEP --> keep the extra bits" msgstr "" #: ../../howto/enum.rst:1198 msgid "keeps Flag status and extra bits" msgstr "" #: ../../howto/enum.rst:1199 msgid "extra bits do not show up in iteration" msgstr "" #: ../../howto/enum.rst:1200 msgid "extra bits do show up in repr() and str()" msgstr "" #: ../../howto/enum.rst:1202 msgid "" "The default for Flag is ``STRICT``, the default for ``IntFlag`` is " "``EJECT``, and the default for ``_convert_`` is ``KEEP`` (see ``ssl." "Options`` for an example of when ``KEEP`` is needed)." msgstr "" #: ../../howto/enum.rst:1210 msgid "How are Enums and Flags different?" msgstr "EnumとFlagはどう違うのか?" #: ../../howto/enum.rst:1212 msgid "" "Enums have a custom metaclass that affects many aspects of both derived :" "class:`Enum` classes and their instances (members)." msgstr "" "Enum は :class:`Enum` 派生クラスやそれらのインスタンス (メンバー) 双方の多く" "の側面に影響を及ぼすカスタムメタクラスを持っています。" #: ../../howto/enum.rst:1217 msgid "Enum Classes" msgstr "Enum クラス" #: ../../howto/enum.rst:1219 msgid "" "The :class:`EnumType` metaclass is responsible for providing the :meth:" "`~object.__contains__`, :meth:`~object.__dir__`, :meth:`~object.__iter__` " "and other methods that allow one to do things with an :class:`Enum` class " "that fail on a typical class, such as ``list(Color)`` or ``some_enum_var in " "Color``. :class:`EnumType` is responsible for ensuring that various other " "methods on the final :class:`Enum` class are correct (such as :meth:`~object." "__new__`, :meth:`~object.__getnewargs__`, :meth:`~object.__str__` and :meth:" "`~object.__repr__`)." msgstr "" #: ../../howto/enum.rst:1228 msgid "Flag Classes" msgstr "Flag クラス" #: ../../howto/enum.rst:1230 msgid "" "Flags have an expanded view of aliasing: to be canonical, the value of a " "flag needs to be a power-of-two value, and not a duplicate name. So, in " "addition to the :class:`Enum` definition of alias, a flag with no value (a.k." "a. ``0``) or with more than one power-of-two value (e.g. ``3``) is " "considered an alias." msgstr "" #: ../../howto/enum.rst:1236 msgid "Enum Members (aka instances)" msgstr "Enum メンバー (インスタンス)" #: ../../howto/enum.rst:1238 msgid "" "The most interesting thing about enum members is that they are singletons. :" "class:`EnumType` creates them all while it is creating the enum class " "itself, and then puts a custom :meth:`~object.__new__` in place to ensure " "that no new ones are ever instantiated by returning only the existing member " "instances." msgstr "" #: ../../howto/enum.rst:1244 msgid "Flag Members" msgstr "Flag メンバー" #: ../../howto/enum.rst:1246 msgid "" "Flag members can be iterated over just like the :class:`Flag` class, and " "only the canonical members will be returned. For example::" msgstr "" "フラグのメンバーは、:class:`Flag` クラスと同様に反復処理することができ、正規" "のメンバーのみが返されます。 例えば::" #: ../../howto/enum.rst:1249 msgid "" ">>> list(Color)\n" "[, , ]" msgstr "" #: ../../howto/enum.rst:1252 msgid "(Note that ``BLACK``, ``PURPLE``, and ``WHITE`` do not show up.)" msgstr "(``BLACK`` 、 ``PURPLE`` 、 ``WHITE`` は表示されないことに注意。)" #: ../../howto/enum.rst:1254 msgid "" "Inverting a flag member returns the corresponding positive value, rather " "than a negative value --- for example::" msgstr "" "フラグのメンバーを反転させると、負の値ではなく、対応する正の値が返されます::" #: ../../howto/enum.rst:1257 msgid "" ">>> ~Color.RED\n" "" msgstr "" #: ../../howto/enum.rst:1260 msgid "" "Flag members have a length corresponding to the number of power-of-two " "values they contain. For example::" msgstr "" "フラグのメンバーは、それが含む2のべき乗の値の数に対応するlengthを持ちます。 " "例えば::" #: ../../howto/enum.rst:1263 msgid "" ">>> len(Color.PURPLE)\n" "2" msgstr "" #: ../../howto/enum.rst:1270 msgid "Enum Cookbook" msgstr "Enum クックブック" #: ../../howto/enum.rst:1273 msgid "" "While :class:`Enum`, :class:`IntEnum`, :class:`StrEnum`, :class:`Flag`, and :" "class:`IntFlag` are expected to cover the majority of use-cases, they cannot " "cover them all. Here are recipes for some different types of enumerations " "that can be used directly, or as examples for creating one's own." msgstr "" ":class:`Enum`, :class:`IntEnum`, :class:`StrEnum`, :class:`Flag`, :class:" "`IntFlag` は用途の大部分をカバーすると予想されますが、そのすべてをカバーでき" "ているわけではありません。ここでは、そのまま、あるいは独自の列挙型を作る例と" "して使える、様々なタイプの列挙型を紹介します。" #: ../../howto/enum.rst:1280 msgid "Omitting values" msgstr "値の省略" #: ../../howto/enum.rst:1282 msgid "" "In many use-cases, one doesn't care what the actual value of an enumeration " "is. There are several ways to define this type of simple enumeration:" msgstr "" "多くの用途では、列挙型の実際の値が何かは気にされません。\n" "このタイプの単純な列挙型を定義する方法はいくつかあります:" #: ../../howto/enum.rst:1285 msgid "use instances of :class:`auto` for the value" msgstr "値に :class:`auto` インスタンスを使用する" #: ../../howto/enum.rst:1286 msgid "use instances of :class:`object` as the value" msgstr "値として :class:`object` インスタンスを使用する" #: ../../howto/enum.rst:1287 msgid "use a descriptive string as the value" msgstr "値として解説文字列を使用する" #: ../../howto/enum.rst:1288 msgid "" "use a tuple as the value and a custom :meth:`~object.__new__` to replace the " "tuple with an :class:`int` value" msgstr "" #: ../../howto/enum.rst:1291 msgid "" "Using any of these methods signifies to the user that these values are not " "important, and also enables one to add, remove, or reorder members without " "having to renumber the remaining members." msgstr "" "これらのどの方法を使ってもユーザーに対して、値は重要ではなく、他のメンバーの" "番号の振り直しをする必要無しに、メンバーの追加、削除、並べ替えが行えるという" "ことを示せます。" #: ../../howto/enum.rst:1297 msgid "Using :class:`auto`" msgstr ":class:`auto` を使う" #: ../../howto/enum.rst:1299 msgid "Using :class:`auto` would look like::" msgstr ":class:`auto` を使うと次のようになります::" #: ../../howto/enum.rst:1301 msgid "" ">>> class Color(Enum):\n" "... RED = auto()\n" "... BLUE = auto()\n" "... GREEN = auto()\n" "...\n" ">>> Color.GREEN\n" "" msgstr "" #: ../../howto/enum.rst:1311 msgid "Using :class:`object`" msgstr ":class:`object` を使う" #: ../../howto/enum.rst:1313 msgid "Using :class:`object` would look like::" msgstr ":class:`object` を使うと次のようになります::" #: ../../howto/enum.rst:1315 msgid "" ">>> class Color(Enum):\n" "... RED = object()\n" "... GREEN = object()\n" "... BLUE = object()\n" "...\n" ">>> Color.GREEN\n" ">" msgstr "" #: ../../howto/enum.rst:1323 msgid "" "This is also a good example of why you might want to write your own :meth:" "`~object.__repr__`::" msgstr "" #: ../../howto/enum.rst:1326 msgid "" ">>> class Color(Enum):\n" "... RED = object()\n" "... GREEN = object()\n" "... BLUE = object()\n" "... def __repr__(self):\n" "... return \"<%s.%s>\" % (self.__class__.__name__, self._name_)\n" "...\n" ">>> Color.GREEN\n" "" msgstr "" #: ../../howto/enum.rst:1339 msgid "Using a descriptive string" msgstr "解説文字列を使う" #: ../../howto/enum.rst:1341 msgid "Using a string as the value would look like::" msgstr "値として文字列を使うと次のようになります::" #: ../../howto/enum.rst:1343 msgid "" ">>> class Color(Enum):\n" "... RED = 'stop'\n" "... GREEN = 'go'\n" "... BLUE = 'too fast!'\n" "...\n" ">>> Color.GREEN\n" "" msgstr "" #: ../../howto/enum.rst:1353 msgid "Using a custom :meth:`~object.__new__`" msgstr "" #: ../../howto/enum.rst:1355 msgid "Using an auto-numbering :meth:`~object.__new__` would look like::" msgstr "" #: ../../howto/enum.rst:1357 msgid "" ">>> class AutoNumber(Enum):\n" "... def __new__(cls):\n" "... value = len(cls.__members__) + 1\n" "... obj = object.__new__(cls)\n" "... obj._value_ = value\n" "... return obj\n" "...\n" ">>> class Color(AutoNumber):\n" "... RED = ()\n" "... GREEN = ()\n" "... BLUE = ()\n" "...\n" ">>> Color.GREEN\n" "" msgstr "" #: ../../howto/enum.rst:1372 msgid "" "To make a more general purpose ``AutoNumber``, add ``*args`` to the " "signature::" msgstr "" "``AutoNumber`` をより広い用途で使うには、シグニチャに ``*args`` を追加しま" "す::" #: ../../howto/enum.rst:1374 msgid "" ">>> class AutoNumber(Enum):\n" "... def __new__(cls, *args): # this is the only change from above\n" "... value = len(cls.__members__) + 1\n" "... obj = object.__new__(cls)\n" "... obj._value_ = value\n" "... return obj\n" "..." msgstr "" #: ../../howto/enum.rst:1382 msgid "" "Then when you inherit from ``AutoNumber`` you can write your own " "``__init__`` to handle any extra arguments::" msgstr "" "``AutoNumber`` を継承すると、追加の引数を取り扱える独自の ``__init__`` が書け" "ます。" #: ../../howto/enum.rst:1385 msgid "" ">>> class Swatch(AutoNumber):\n" "... def __init__(self, pantone='unknown'):\n" "... self.pantone = pantone\n" "... AUBURN = '3497'\n" "... SEA_GREEN = '1246'\n" "... BLEACHED_CORAL = () # New color, no Pantone code yet!\n" "...\n" ">>> Swatch.SEA_GREEN\n" "\n" ">>> Swatch.SEA_GREEN.pantone\n" "'1246'\n" ">>> Swatch.BLEACHED_CORAL.pantone\n" "'unknown'" msgstr "" #: ../../howto/enum.rst:1401 msgid "" "The :meth:`~object.__new__` method, if defined, is used during creation of " "the Enum members; it is then replaced by Enum's :meth:`~object.__new__` " "which is used after class creation for lookup of existing members." msgstr "" #: ../../howto/enum.rst:1407 msgid "" "*Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the " "one that is found; instead, use the data type directly -- e.g.::" msgstr "" #: ../../howto/enum.rst:1410 msgid "obj = int.__new__(cls, value)" msgstr "" #: ../../howto/enum.rst:1414 msgid "OrderedEnum" msgstr "OrderedEnum" #: ../../howto/enum.rst:1416 msgid "" "An ordered enumeration that is not based on :class:`IntEnum` and so " "maintains the normal :class:`Enum` invariants (such as not being comparable " "to other enumerations)::" msgstr "" ":class:`IntEnum` をベースとしないため、通常の :class:`Enum` の不変条件 (他の" "列挙型と比較できないなど) のままで、メンバーを順序付けできる列挙型です::" #: ../../howto/enum.rst:1420 msgid "" ">>> class OrderedEnum(Enum):\n" "... def __ge__(self, other):\n" "... if self.__class__ is other.__class__:\n" "... return self.value >= other.value\n" "... return NotImplemented\n" "... def __gt__(self, other):\n" "... if self.__class__ is other.__class__:\n" "... return self.value > other.value\n" "... return NotImplemented\n" "... def __le__(self, other):\n" "... if self.__class__ is other.__class__:\n" "... return self.value <= other.value\n" "... return NotImplemented\n" "... def __lt__(self, other):\n" "... if self.__class__ is other.__class__:\n" "... return self.value < other.value\n" "... return NotImplemented\n" "...\n" ">>> class Grade(OrderedEnum):\n" "... A = 5\n" "... B = 4\n" "... C = 3\n" "... D = 2\n" "... F = 1\n" "...\n" ">>> Grade.C < Grade.A\n" "True" msgstr "" #: ../../howto/enum.rst:1450 msgid "DuplicateFreeEnum" msgstr "DuplicateFreeEnum" #: ../../howto/enum.rst:1452 msgid "" "Raises an error if a duplicate member value is found instead of creating an " "alias::" msgstr "" "値が重複するメンバーがある場合に、エイリアスを作成するのではなくエラーを発生" "させます::" #: ../../howto/enum.rst:1455 msgid "" ">>> class DuplicateFreeEnum(Enum):\n" "... def __init__(self, *args):\n" "... cls = self.__class__\n" "... if any(self.value == e.value for e in cls):\n" "... a = self.name\n" "... e = cls(self.value).name\n" "... raise ValueError(\n" "... \"aliases not allowed in DuplicateFreeEnum: %r --> " "%r\"\n" "... % (a, e))\n" "...\n" ">>> class Color(DuplicateFreeEnum):\n" "... RED = 1\n" "... GREEN = 2\n" "... BLUE = 3\n" "... GRENE = 2\n" "...\n" "Traceback (most recent call last):\n" " ...\n" "ValueError: aliases not allowed in DuplicateFreeEnum: 'GRENE' --> 'GREEN'" msgstr "" #: ../../howto/enum.rst:1477 msgid "" "This is a useful example for subclassing Enum to add or change other " "behaviors as well as disallowing aliases. If the only desired change is " "disallowing aliases, the :func:`unique` decorator can be used instead." msgstr "" "これは Enum に別名を無効にするのと同様な振る舞いの追加や変更をおこなうための" "サブクラス化に役立つ例です。単に別名を無効にしたいだけなら、 :func:`unique` " "デコレーターを使用して行えます。" #: ../../howto/enum.rst:1483 msgid "MultiValueEnum" msgstr "" #: ../../howto/enum.rst:1485 msgid "Supports having more than one value per member::" msgstr "" #: ../../howto/enum.rst:1487 msgid "" ">>> class MultiValueEnum(Enum):\n" "... def __new__(cls, value, *values):\n" "... self = object.__new__(cls)\n" "... self._value_ = value\n" "... for v in values:\n" "... self._add_value_alias_(v)\n" "... return self\n" "...\n" ">>> class DType(MultiValueEnum):\n" "... float32 = 'f', 8\n" "... double64 = 'd', 9\n" "...\n" ">>> DType('f')\n" "\n" ">>> DType(9)\n" "" msgstr "" #: ../../howto/enum.rst:1506 msgid "Planet" msgstr "Planet" #: ../../howto/enum.rst:1508 msgid "" "If :meth:`~object.__new__` or :meth:`~object.__init__` is defined, the value " "of the enum member will be passed to those methods::" msgstr "" #: ../../howto/enum.rst:1511 msgid "" ">>> class Planet(Enum):\n" "... MERCURY = (3.303e+23, 2.4397e6)\n" "... VENUS = (4.869e+24, 6.0518e6)\n" "... EARTH = (5.976e+24, 6.37814e6)\n" "... MARS = (6.421e+23, 3.3972e6)\n" "... JUPITER = (1.9e+27, 7.1492e7)\n" "... SATURN = (5.688e+26, 6.0268e7)\n" "... URANUS = (8.686e+25, 2.5559e7)\n" "... NEPTUNE = (1.024e+26, 2.4746e7)\n" "... def __init__(self, mass, radius):\n" "... self.mass = mass # in kilograms\n" "... self.radius = radius # in meters\n" "... @property\n" "... def surface_gravity(self):\n" "... # universal gravitational constant (m3 kg-1 s-2)\n" "... G = 6.67300E-11\n" "... return G * self.mass / (self.radius * self.radius)\n" "...\n" ">>> Planet.EARTH.value\n" "(5.976e+24, 6378140.0)\n" ">>> Planet.EARTH.surface_gravity\n" "9.802652743337129" msgstr "" #: ../../howto/enum.rst:1537 msgid "TimePeriod" msgstr "TimePeriod" #: ../../howto/enum.rst:1539 msgid "An example to show the :attr:`~Enum._ignore_` attribute in use::" msgstr "" #: ../../howto/enum.rst:1541 msgid "" ">>> from datetime import timedelta\n" ">>> class Period(timedelta, Enum):\n" "... \"different lengths of time\"\n" "... _ignore_ = 'Period i'\n" "... Period = vars()\n" "... for i in range(367):\n" "... Period['day_%d' % i] = i\n" "...\n" ">>> list(Period)[:2]\n" "[, ]\n" ">>> list(Period)[-2:]\n" "[, ]" msgstr "" #: ../../howto/enum.rst:1558 msgid "Subclassing EnumType" msgstr "EnumType のサブクラスを作る" #: ../../howto/enum.rst:1560 msgid "" "While most enum needs can be met by customizing :class:`Enum` subclasses, " "either with class decorators or custom functions, :class:`EnumType` can be " "subclassed to provide a different Enum experience." msgstr ""
X Tutup