(
field: Field,
enclosing_messages: Optional[List[Message]] = None,
)
| 461 | ) |
| 462 | |
| 463 | def check_field( |
| 464 | field: Field, |
| 465 | enclosing_messages: Optional[List[Message]] = None, |
| 466 | ) -> None: |
| 467 | if is_any_type(field.field_type) and field.ref: |
| 468 | self._error( |
| 469 | "ref is not allowed on any fields", |
| 470 | field.location, |
| 471 | ) |
| 472 | |
| 473 | if ( |
| 474 | isinstance(field.field_type, ListType) |
| 475 | and is_any_type(field.field_type.element_type) |
| 476 | and field.element_ref |
| 477 | ): |
| 478 | self._error( |
| 479 | "ref is not allowed on list<any> fields", |
| 480 | field.location, |
| 481 | ) |
| 482 | |
| 483 | if ( |
| 484 | isinstance(field.field_type, MapType) |
| 485 | and is_any_type(field.field_type.value_type) |
| 486 | and field.field_type.value_ref |
| 487 | ): |
| 488 | self._error( |
| 489 | "ref is not allowed on map values of any type", |
| 490 | field.location, |
| 491 | ) |
| 492 | |
| 493 | if field.ref: |
| 494 | if isinstance(field.field_type, (ListType, MapType)): |
| 495 | self._error( |
| 496 | "ref is not allowed on list/map fields; " |
| 497 | "use `list<ref T>` (or `repeated ref T`) for list elements or `map<..., ref T>` for map values", |
| 498 | field.location, |
| 499 | ) |
| 500 | else: |
| 501 | ensure_message_or_union( |
| 502 | field.field_type, |
| 503 | field, |
| 504 | enclosing_messages, |
| 505 | "ref", |
| 506 | ) |
| 507 | |
| 508 | if field.element_ref: |
| 509 | if not isinstance(field.field_type, ListType): |
| 510 | self._error( |
| 511 | "`list<ref T>` (or `repeated ref T`) is only valid for list fields", |
| 512 | field.location, |
| 513 | ) |
| 514 | else: |
| 515 | ensure_message_or_union( |
| 516 | field.field_type.element_type, |
| 517 | field, |
| 518 | enclosing_messages, |
| 519 | "ref", |
| 520 | ) |
nothing calls this directly
no test coverage detected