Python 2.7은 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
Field 클래스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Field 클래스는 메시지에 정의된 모든 필드의 기본 클래스입니다. 개발자가 이 클래스를 확장할 수 없습니다.
Field
는 protorpc.messages
모듈에서 제공됩니다.
생성자
Field 클래스의 생성자는 다음과 같이 정의됩니다.
- class Field(message_type, number, [required=False | repeated=False], variant=None, default=None)
-
Field 인스턴스를 초기화합니다. Field의 각 하위 클래스는 다음을 정의해야 합니다.
VARIANTS
- 해당 필드에서 허용되는 변형 유형 집합입니다.
DEFAULT_VARIANT
- 생성자에서 지정되지 않은 경우, 기본 변형 유형입니다.
인수
- 숫자
- 필드 번호입니다. 메시지 클래스마다 고유해야 합니다.
- required=False
- 이 필드가 필수인지 여부입니다.
repeated
인수와 상호 배타적입니다. required
를 사용하는 경우 repeated
를 지정하지 마세요.
- repeated=False
- 이 필드가 반복되는지 여부입니다.
required
인수와 상호 배타적입니다. repeated=True
를 사용하는 경우 required=True
를 지정하지 마세요.
- variant=None
- 주로 프로토콜 버퍼에 사용되는 추가 인코딩 정보를 제공합니다. 이러한 변형은
descriptor.proto
의 Type 값에 매핑됩니다. 권장사항은 기본값을 사용하는 것이지만 32비트, 64비트, 부호 없는 형식 등의 값을 지정할 수 있습니다.
- default=None
- 기본 요청에 없는 경우, 필드의 기본값입니다.
참고: 반복 필드 또는 메시지 필드에는 기본값이 허용되지 않습니다.
다음과 같은 예외가 발생합니다.
클래스 속성
FieldList 클래스에는 속성이 한 개 있습니다.
- default()
- 필드의 기본값입니다.
인스턴스 메소드
FieldList 인스턴스에는 다음과 같은 메소드가 있습니다.
- validate(value)
- 필드에 할당된 값 유효성을 검사합니다.
인수
- value
- 평가할 값입니다.
값이 예상 유형이 아닌 경우 ValidationError가 발생합니다.
- validate_default_element(value)
-
기본 필드에 할당된 값 유효성을 검사합니다. 단일 요소에만 해당됩니다.
순환 정의 참조의 경우, 일부 필드는 필요한 기본 유형의 지연된 확인을 허용할 수 있습니다. 이런 경우, 기본값은 모든 메시지 클래스를 정의한 후 필요할 때 확인되는 자리표시자일 수 있습니다.
인수
- value
- 유효성을 검사할 기본값입니다.
값이 예상 유형이 아닌 경우 ValidationError가 발생합니다.
- validate_default(value)
-
필드의 기본값 유효성을 검사합니다.
인수
- value
- 유효성을 검사할 기본값입니다.
값이 예상 유형이 아닌 경우 ValidationError가 발생합니다.
- message_definition()
-
이 필드 정의를 포함하는 메시지 정의를 가져옵니다. Field가 포함된 Message 객체의 정의를 반환합니다. Field가 메시지 클래스 외부에 정의된 경우 None을 반환합니다.
값이 예상 유형이 아닌 경우 ValidationError가 발생합니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 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\u003eField\u003c/code\u003e class serves as the foundation for all fields within messages and cannot be extended by developers, and is provided by the \u003ccode\u003eprotorpc.messages\u003c/code\u003e module.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eField\u003c/code\u003e constructor takes parameters like \u003ccode\u003enumber\u003c/code\u003e, \u003ccode\u003erequired\u003c/code\u003e, \u003ccode\u003erepeated\u003c/code\u003e, \u003ccode\u003evariant\u003c/code\u003e, and \u003ccode\u003edefault\u003c/code\u003e to define field properties, and raises exceptions for invalid inputs, such as an invalid default, or mutually exclusive arguments.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eField\u003c/code\u003e class contains \u003ccode\u003eVARIANTS\u003c/code\u003e and \u003ccode\u003eDEFAULT_VARIANT\u003c/code\u003e properties that define the field's acceptable variant types, and its default variant type respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eField\u003c/code\u003e instance methods include \u003ccode\u003evalidate\u003c/code\u003e, \u003ccode\u003evalidate_default_element\u003c/code\u003e, \u003ccode\u003evalidate_default\u003c/code\u003e to check values against expectations, and \u003ccode\u003emessage_definition\u003c/code\u003e to find the \u003ccode\u003eMessage\u003c/code\u003e that contains the Field.\u003c/p\u003e\n"],["\u003cp\u003eDefault values for Fields are not permitted for repeated fields or message fields, as specified by the argument \u003ccode\u003edefault=None\u003c/code\u003e in the constructor.\u003c/p\u003e\n"]]],[],null,["# The Field Class\n\nThe Field class is the base class for all fields defined on messages. This class cannot be extended by developers.\n\n`Field` is provided by the `protorpc.messages` module.\n\nConstructor\n-----------\n\nThe constructor of the Field class is defined as follows:\n\nclass\nField\n(message_type,\nnumber,\n\\[required=False \\| repeated=False\\], variant=None, default=None)\n\n: Initializes an Field instance. Each sub-class of Field must define the following:\n\n `VARIANTS`\n : Set of variant types accepted by that field.\n\n `DEFAULT_VARIANT`\n : Default variant type if not specified in constructor.\n **Arguments**\n\n number\n : Number of the field. Must be unique per message class.\n\n required=False\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=False\n : Whether or not this field is repeated. Mutually exclusive with the `required` argument; do not specify `required=True` if you also use `repeated=True`.\n\n variant=None\n : Provides additional encoding information that is mainly used by protocol buffers. These variants map to the Type values in `descriptor.proto`. Best practice is to use default values, but you can specify values as 32-bit, 64-bit, unsigned, etc.\n\n default=None\n\n : Default value for the field if not found in the underlying request. **Note:** Default values are not permitted for repeated fields or message fields.\n\n Raises the following exceptions:\n\n - [InvalidVariantError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#InvalidVariantError) when invalid variant for field is provided.\n - [InvalidDefaultError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#InvalidDefaultError) when invalid default for field is provided.\n - [FieldDefinitionError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#FieldDefinitionError) when invalid number provided or mutually exclusive fields are used.\n - [InvalidNumberError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#InvalidNumberError) when the field number is out of range or reserved.\n\nClass Property\n--------------\n\nThe FieldList class has one property:\n\ndefault()\n: The default value for the field.\n\nInstance Methods\n----------------\n\nFieldList instances have the following methods:\n\nvalidate(value)\n: Validates a value assigned to a field.\n **Arguments**\n\n value\n : The value to evaluate.\n\n Raises a [ValidationError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#ValidationError) if the value is not an expected type.\n\nvalidate_default_element(value)\n\n: Validates a value assigned to a default field. Specific to a single element.\n\n Some fields may allow for delayed resolution of default types necessary in the case of circular definition references. In this case, the default value might be a placeholder that is resolved when needed after all the message classes are defined.\n **Arguments**\n\n value\n : Default value to validate.\n\n Raises a [ValidationError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#ValidationError) if the value is not an expected type.\n\nvalidate_default(value)\n\n: Validates that a field's default value.\n\n **Arguments**\n\n value\n : Default value to validate.\n\n Raises a [ValidationError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#ValidationError) if the value is not an expected type.\n\nmessage_definition()\n\n: Gets a message definition that contains this Field definition. Returns a definition for the [Message](/appengine/docs/legacy/standard/python/tools/protorpc/messages/messageclass) object that contains the Field. Returns None if Field is defined outside of a message class.\n\n Raises a [ValidationError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#ValidationError) if the value is not an expected type."]]