MCPcopy
hub / github.com/pydantic/pydantic / _field_name_for_signature

Function _field_name_for_signature

pydantic/_internal/_signature.py:26–44  ·  view source on GitHub ↗

Extract the correct name to use for the field when generating a signature. Assuming the field has a valid alias, this will return the alias. Otherwise, it will return the field name. First priority is given to the alias, then the validation_alias, then the field name. Args: fie

(field_name: str, field_info: FieldInfo)

Source from the content-addressed store, hash-verified

24
25
26def _field_name_for_signature(field_name: str, field_info: FieldInfo) -> str:
27 """Extract the correct name to use for the field when generating a signature.
28
29 Assuming the field has a valid alias, this will return the alias. Otherwise, it will return the field name.
30 First priority is given to the alias, then the validation_alias, then the field name.
31
32 Args:
33 field_name: The name of the field
34 field_info: The corresponding FieldInfo object.
35
36 Returns:
37 The correct name to use when generating a signature.
38 """
39 if isinstance(field_info.alias, str) and is_valid_identifier(field_info.alias):
40 return field_info.alias
41 if isinstance(field_info.validation_alias, str) and is_valid_identifier(field_info.validation_alias):
42 return field_info.validation_alias
43
44 return field_name
45
46
47def _process_param_defaults(param: Parameter) -> Parameter:

Callers 2

_process_param_defaultsFunction · 0.85

Calls 1

is_valid_identifierFunction · 0.70

Tested by

no test coverage detected