MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _AttrGetter

Class _AttrGetter

lib/sqlalchemy/orm/mapped_collection.py:201–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199
200
201class _AttrGetter:
202 __slots__ = ("attr_name", "getter")
203
204 def __init__(self, attr_name: str):
205 self.attr_name = attr_name
206 self.getter = operator.attrgetter(attr_name)
207
208 def __call__(self, mapped_object: Any) -> Any:
209 obj = self.getter(mapped_object)
210 if obj is None:
211 state = base.instance_state(mapped_object)
212 mp = state.mapper
213 if self.attr_name in mp.attrs:
214 dict_ = state.dict
215 obj = dict_.get(self.attr_name, base.NO_VALUE)
216 if obj is None:
217 return Missing
218 else:
219 return Missing
220
221 return obj
222
223 def __reduce__(self) -> Tuple[Type[_AttrGetter], Tuple[str]]:
224 return _AttrGetter, (self.attr_name,)
225
226
227def attribute_keyed_dict(

Callers 1

attribute_keyed_dictFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected