MCPcopy Index your code
hub / github.com/nonebot/nonebot2 / FieldInfo

Class FieldInfo

nonebot/compat.py:121–153  ·  view source on GitHub ↗

FieldInfo class with extra property for compatibility with pydantic v1

Source from the content-addressed store, hash-verified

119 LegacyUnionField.__doc__ = "Mark field to use legacy left to right union mode"
120
121 class FieldInfo(BaseFieldInfo): # pyright: ignore[reportGeneralTypeIssues]
122 """FieldInfo class with extra property for compatibility with pydantic v1"""
123
124 # make default can be positional argument
125 def __init__(self, default: Any = PydanticUndefined, **kwargs: Any) -> None:
126 super().__init__(default=default, **kwargs)
127
128 @property
129 def extra(self) -> dict[str, Any]:
130 """Extra data that is not part of the standard pydantic fields.
131
132 For compatibility with pydantic v1.
133 """
134 # extract extra data from attributes set except used slots
135 # we need to call super in advance due to
136 # comprehension not inlined in cpython < 3.12
137 # https://peps.python.org/pep-0709/
138 slots = super().__slots__
139 return {k: v for k, v in self._attributes_set.items() if k not in slots}
140
141 @classmethod
142 def _inherit_construct(
143 cls, field_info: BaseFieldInfo | None = None, **kwargs: Any
144 ) -> Self:
145 init_kwargs = {}
146 if field_info:
147 init_kwargs.update(field_info._attributes_set)
148 init_kwargs.update(kwargs)
149
150 instance = cls(**init_kwargs)
151 if field_info:
152 instance.metadata = field_info.metadata
153 return instance
154
155 @dataclass
156 class ModelField:

Callers 6

_check_paramMethod · 0.90
_check_paramMethod · 0.90
_check_paramMethod · 0.90
test_field_infoFunction · 0.90
test_type_adapterFunction · 0.90
constructMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_field_infoFunction · 0.72
test_type_adapterFunction · 0.72