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

Function remove

lib/sqlalchemy/event/api.py:171–214  ·  view source on GitHub ↗

Remove an event listener. The arguments here should match exactly those which were sent to :func:`.listen`; all the event registration which proceeded as a result of this call will be reverted by calling :func:`.remove` with the same arguments. e.g.:: # if a function w

(target: Any, identifier: str, fn: Callable[..., Any])

Source from the content-addressed store, hash-verified

169
170
171def remove(target: Any, identifier: str, fn: Callable[..., Any]) -> None:
172 """Remove an event listener.
173
174 The arguments here should match exactly those which were sent to
175 :func:`.listen`; all the event registration which proceeded as a result
176 of this call will be reverted by calling :func:`.remove` with the same
177 arguments.
178
179 e.g.::
180
181 # if a function was registered like this...
182 @event.listens_for(SomeMappedClass, "before_insert", propagate=True)
183 def my_listener_function(*arg):
184 pass
185
186
187 # ... it's removed like this
188 event.remove(SomeMappedClass, "before_insert", my_listener_function)
189
190 Above, the listener function associated with ``SomeMappedClass`` was also
191 propagated to subclasses of ``SomeMappedClass``; the :func:`.remove`
192 function will revert all of these operations.
193
194 .. note::
195
196 The :func:`.remove` function cannot be called at the same time
197 that the target event is being run. This has implications
198 for thread safety, and also means an event cannot be removed
199 from inside the listener function for itself. The list of
200 events to be run are present inside of a mutable collection
201 that can't be changed during iteration.
202
203 Event registration and removal is not intended to be a "high
204 velocity" operation; it is a configurational operation. For
205 systems that need to quickly associate and deassociate with
206 events at high scale, use a mutable structure that is handled
207 from inside of a single listener.
208
209 .. seealso::
210
211 :func:`.listen`
212
213 """
214 _event_key(target, identifier, fn).remove()
215
216
217def contains(target: Any, identifier: str, fn: Callable[..., Any]) -> bool:

Callers

nothing calls this directly

Calls 2

_event_keyFunction · 0.85
removeMethod · 0.45

Tested by

no test coverage detected