MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / set_attribute

Function set_attribute

lib/sqlalchemy/orm/attributes.py:2766–2795  ·  view source on GitHub ↗

Set the value of an attribute, firing history events. This function may be used regardless of instrumentation applied directly to the class, i.e. no descriptors are required. Custom attribute management schemes will need to make usage of this method to establish attribute state as u

(
    instance: object,
    key: str,
    value: Any,
    initiator: Optional[AttributeEventToken] = None,
)

Source from the content-addressed store, hash-verified

2764
2765
2766def set_attribute(
2767 instance: object,
2768 key: str,
2769 value: Any,
2770 initiator: Optional[AttributeEventToken] = None,
2771) -> None:
2772 """Set the value of an attribute, firing history events.
2773
2774 This function may be used regardless of instrumentation
2775 applied directly to the class, i.e. no descriptors are required.
2776 Custom attribute management schemes will need to make usage
2777 of this method to establish attribute state as understood
2778 by SQLAlchemy.
2779
2780 :param instance: the object that will be modified
2781
2782 :param key: string name of the attribute
2783
2784 :param value: value to assign
2785
2786 :param initiator: an instance of :class:`.Event` that would have
2787 been propagated from a previous event listener. This argument
2788 is used when the :func:`.set_attribute` function is being used within
2789 an existing event listening function where an :class:`.Event` object
2790 is being supplied; the object may be used to track the origin of the
2791 chain of events.
2792
2793 """
2794 state, dict_ = instance_state(instance), instance_dict(instance)
2795 state.manager[key].impl.set(state, dict_, value, initiator)
2796
2797
2798def get_attribute(instance: object, key: str) -> Any:

Callers 2

__setattr__Method · 0.90
__setattr__Method · 0.90

Calls 3

instance_stateFunction · 0.85
instance_dictFunction · 0.85
setMethod · 0.45

Tested by 1

__setattr__Method · 0.72