MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / set_attribute

Function set_attribute

lib/sqlalchemy/orm/attributes.py:2739–2770  ·  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

2737
2738
2739def set_attribute(
2740 instance: object,
2741 key: str,
2742 value: Any,
2743 initiator: Optional[AttributeEventToken] = None,
2744) -> None:
2745 """Set the value of an attribute, firing history events.
2746
2747 This function may be used regardless of instrumentation
2748 applied directly to the class, i.e. no descriptors are required.
2749 Custom attribute management schemes will need to make usage
2750 of this method to establish attribute state as understood
2751 by SQLAlchemy.
2752
2753 :param instance: the object that will be modified
2754
2755 :param key: string name of the attribute
2756
2757 :param value: value to assign
2758
2759 :param initiator: an instance of :class:`.Event` that would have
2760 been propagated from a previous event listener. This argument
2761 is used when the :func:`.set_attribute` function is being used within
2762 an existing event listening function where an :class:`.Event` object
2763 is being supplied; the object may be used to track the origin of the
2764 chain of events.
2765
2766 .. versionadded:: 1.2.3
2767
2768 """
2769 state, dict_ = instance_state(instance), instance_dict(instance)
2770 state.manager[key].impl.set(state, dict_, value, initiator)
2771
2772
2773def 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