Python 2.7은 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
EnumField 클래스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
EnumField 클래스는 enum 값에 대한 정의를 제공합니다. Enum 필드에는 연결된 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의 서브클래스여야 합니다.
- 숫자
- 필드의 숫자입니다. 메시지 클래스별로 고유해야 합니다.
- required
- 이 필드가 필수인지 여부입니다.
repeated
인수와 상호 배타적입니다. required
를 사용하는 경우 repeated
를 지정하지 마세요.
- repeated
- 이 필드가 반복되는지 여부입니다.
required
인수와 상호 배타적입니다. repeated
를 사용하는 경우 required
를 지정하지 마세요.
- variant
- 필드 유형을 추가로 지정합니다. 일부 필드 유형은 기본 전송 형식을 기준으로 추가로 제한됩니다. 기본값을 사용하는 것이 가장 좋지만 개발자는 이 필드를 사용하여 정수 필드를 32비트 정수 또는 기본 64비트로 선언할 수 있습니다.
- default
- 스트림에서 찾을 수 없는 경우 필드에 사용할 기본값입니다.
enum_type
이 유효하지 않으면 FieldDefinitionError가 발생합니다.
클래스 속성
EnumField 클래스는 다음 클래스 속성을 제공합니다.
- type()
- 필드에 사용되는 Enum 유형입니다.
- default()
- enum 필드의 기본값입니다. 기본값이 확인되지 않는 경우 Enum 유형을 기본값으로 사용합니다.
인스턴스 메소드
EnumField 인스턴스에는 다음과 같은 메소드가 있습니다.
- validate_default_element(value)
- Enum 필드의 기본 요소에 대한 유효성을 검사합니다. Enum 필드는 필드 유형이 확인되지 않은 경우 지연된 기본값 확인을 허용합니다. 필드의 기본값은 문자열이거나 정수일 수 있습니다. 필드의 Enum 유형이 확인된 경우 해당 유형에 대해 기본값의 유효성이 검사됩니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(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-09-04(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,["# The EnumField Class\n\nThe EnumField class provides definitions for enum values. Enum fields may have default values that are delayed until the associated enum type is resolved. This is necessary to support certain circular references. For example: \n\n```python\nfrom protorpc import messages\n\nclass Message1(messages.Message):\n\n class Color(messages.Enum):\n RED = 1\n GREEN = 2\n BLUE = 3\n\n # Validate this field's default value when default is accessed.\n animal = messages.EnumField('Message2.Animal', 1, default='HORSE')\n\nclass Message2(messages.Message):\n\n class Animal(messages.Enum):\n DOG = 1\n CAT = 2\n HORSE = 3\n\n # This fields default value will be validated right away since Color is\n # already fully resolved.\n color = messages.EnumField(Message1.Color, 1, default='RED')\n```\n\n`EnumField` is provided by the `protorpc.messages` module.\n\nConstructor\n-----------\n\nThe constructor of the EnumField class is defined as follows:\n\nclass EnumField(enum_type, number, required, repeated, variant, default)\n\n: Provides a field definition for Enum values.\n\n **Arguments**\n\n enum_type\n : The Enum type for a field. Must be a subclass of [Enum](/appengine/docs/legacy/standard/python/tools/protorpc/messages/enumclass).\n\n number\n : The number of the field. Must be unique per message class.\n\n required\n : Whether or not this field is required. Mutually exclusive with the `repeated` argument; do not specify `repeated` if you use `required`.\n\n repeated\n : Whether or not this field is repeated. Mutually exclusive with the `required` argument; do not specify `required` if you use `repeated`.\n\n variant\n : Further specifies the type of field. Some field types are further restrained based on the underlying wire format. Best practice is to use the default value, but developers can use this field to declare an integer field as a 32-bit integer vs. the default 64 bit.\n\n default\n : Default value to use for the field if it is not found in stream.\n\n Raises a [FieldDefinitionError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#FieldDefinitionError) when `enum_type` is invalid.\n\nClass Properties\n----------------\n\nThe EnumField class provides the following class properties:\n\ntype()\n: Enum type used for the field.\n\ndefault()\n: Default for the enum field. If the default value is unresolved, uses Enum [type](#type) as the default.\n\nInstance Methods\n----------------\n\nEnumField instances have the following method:\n\nvalidate_default_element(value)\n: Validates the default element of the Enum field. Enum fields allow for delayed resolution of default values when the type of the field has not been resolved. The default value of a field may be a string or an integer. If the Enum type of the field has been resolved, the default value is validated against that type."]]