Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
EnumField クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
EnumField クラスは、列挙値の定義を提供します。Enum フィールドは、関連付けられた列挙型が解決されるまで遅延されるデフォルト値を持つことができます。これは特定の循環参照をサポートするために必要です。次に例を示します。
from protorpc import messages
class Message1(messages.Message):
class Color(messages.Enum):
RED = 1
GREEN = 2
BLUE = 3
# Validate this field's default value when default is accessed.
animal = messages.EnumField('Message2.Animal', 1, default='HORSE')
class Message2(messages.Message):
class Animal(messages.Enum):
DOG = 1
CAT = 2
HORSE = 3
# This fields default value will be validated right away since Color is
# already fully resolved.
color = messages.EnumField(Message1.Color, 1, default='RED')
EnumField
は protorpc.messages
モジュールによって提供されます。
コンストラクタ
EnumField クラスのコンストラクタは次のように定義されます:
- class EnumField(enum_type, number, required, repeated, variant, default)
-
Enum 値のフィールド定義を提供します。
引数
- enum_type
- フィールドの Enum 型。Enum のサブクラスにする必要があります。
- number
- フィールドの番号。メッセージ クラスごとに一意でなければなりません。
- required
- このフィールドが必須かどうかを指定します。
repeated
引数と同時に指定することはできません。required
を使用する場合は repeated
を指定しないでください。
- repeated
- このフィールドが反復フィールドかどうかを指定します。
required
引数と同時に指定することはできません。repeated
を使用する場合は required
を指定しないでください。
- variant
- フィールドの型を指定します。一部のフィールド型は、基になる送信形式に基づいて制約できます。デフォルト値の使用をおすすめしますが、このフィールドを使用してデフォルトの 64 ビットではなく 32 ビットの整数として整数フィールドを宣言することもできます。
- default
- ストリーム内にフィールドの値が見つからない場合に使用するデフォルト値。
enum_type
が無効な場合、FieldDefinitionError が発生します。
クラスのプロパティ
EnumField クラスには次のクラス プロパティがあります:
- type()
- フィールドに使用する列挙型。
- default()
- 列挙フィールドのデフォルト値です。デフォルト値が解決されない場合は、デフォルトとして Enum 型を使用します。
インスタンス メソッド
EnumField のインスタンスには次のメソッドがあります。
- validate_default_element(value)
- Enum フィールドのデフォルト要素を検証します。Enum フィールドでは、フィールドの型が解決されていない場合にデフォルト値の遅延解決が可能です。フィールドのデフォルト値は文字列または整数になります。フィールドの Enum 型が解決されている場合、その型に基づいてデフォルト値が検証されます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-11 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-11 UTC。"],[[["\u003cp\u003eThe \u003ccode\u003eEnumField\u003c/code\u003e class defines fields for enum values, supporting delayed default value resolution to handle circular references.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eEnumField\u003c/code\u003e is constructed using the enum type, field number, and optional arguments like \u003ccode\u003erequired\u003c/code\u003e, \u003ccode\u003erepeated\u003c/code\u003e, \u003ccode\u003evariant\u003c/code\u003e, and \u003ccode\u003edefault\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003etype()\u003c/code\u003e property returns the Enum type associated with the field, while \u003ccode\u003edefault()\u003c/code\u003e provides the default enum value, or the enum type if the value is unresolved.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003evalidate_default_element(value)\u003c/code\u003e is used to validate the default value, supporting strings or integers, against the resolved Enum type.\u003c/p\u003e\n"],["\u003cp\u003eThe default value for an \u003ccode\u003eEnumField\u003c/code\u003e can be validated at the time it is accessed, and it is provided by the \u003ccode\u003eprotorpc.messages\u003c/code\u003e module.\u003c/p\u003e\n"]]],[],null,[]]