MCPcopy
hub / github.com/danielgtaylor/python-betterproto / dataclass_field

Function dataclass_field

src/betterproto/__init__.py:198–215  ·  view source on GitHub ↗

Creates a dataclass field with attached protobuf metadata.

(
    number: int,
    proto_type: str,
    *,
    map_types: Optional[Tuple[str, str]] = None,
    group: Optional[str] = None,
    wraps: Optional[str] = None,
    optional: bool = False,
)

Source from the content-addressed store, hash-verified

196
197
198def dataclass_field(
199 number: int,
200 proto_type: str,
201 *,
202 map_types: Optional[Tuple[str, str]] = None,
203 group: Optional[str] = None,
204 wraps: Optional[str] = None,
205 optional: bool = False,
206) -> dataclasses.Field:
207 """Creates a dataclass field with attached protobuf metadata."""
208 return dataclasses.field(
209 default=None if optional else PLACEHOLDER,
210 metadata={
211 "betterproto": FieldMetadata(
212 number, proto_type, map_types, group, wraps, optional
213 )
214 },
215 )
216
217
218# Note: the fields below return `Any` to prevent type errors in the generated

Callers 15

enum_fieldFunction · 0.85
bool_fieldFunction · 0.85
int32_fieldFunction · 0.85
int64_fieldFunction · 0.85
uint32_fieldFunction · 0.85
uint64_fieldFunction · 0.85
sint32_fieldFunction · 0.85
sint64_fieldFunction · 0.85
float_fieldFunction · 0.85
double_fieldFunction · 0.85
fixed32_fieldFunction · 0.85
fixed64_fieldFunction · 0.85

Calls 1

FieldMetadataClass · 0.85

Tested by

no test coverage detected