MCPcopy
hub / github.com/pydantic/pydantic / _calculate_keys

Function _calculate_keys

pydantic/deprecated/copy_internals.py:198–224  ·  view source on GitHub ↗
(
    self: BaseModel,
    include: MappingIntStrAny | None,
    exclude: MappingIntStrAny | None,
    exclude_unset: bool,
    update: dict[str, Any] | None = None,  # noqa UP006
)

Source from the content-addressed store, hash-verified

196
197
198def _calculate_keys(
199 self: BaseModel,
200 include: MappingIntStrAny | None,
201 exclude: MappingIntStrAny | None,
202 exclude_unset: bool,
203 update: dict[str, Any] | None = None, # noqa UP006
204) -> typing.AbstractSet[str] | None:
205 if include is None and exclude is None and exclude_unset is False:
206 return None
207
208 keys: typing.AbstractSet[str]
209 if exclude_unset:
210 keys = self.__pydantic_fields_set__.copy()
211 else:
212 keys = set(self.__dict__.keys())
213 keys = keys | (self.__pydantic_extra__ or {}).keys()
214
215 if include is not None:
216 keys &= include.keys()
217
218 if update:
219 keys -= update.keys()
220
221 if exclude:
222 keys -= {k for k, v in exclude.items() if _utils.ValueItems.is_true(v)}
223
224 return keys

Callers 1

_iterFunction · 0.85

Calls 4

keysMethod · 0.80
copyMethod · 0.45
itemsMethod · 0.45
is_trueMethod · 0.45

Tested by

no test coverage detected