MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _assert_required_roles

Function _assert_required_roles

lib/sqlalchemy/orm/collections.py:912–941  ·  view source on GitHub ↗

ensure all roles are present, and apply implicit instrumentation if needed

(cls, roles, methods)

Source from the content-addressed store, hash-verified

910
911
912def _assert_required_roles(cls, roles, methods):
913 """ensure all roles are present, and apply implicit instrumentation if
914 needed
915
916 """
917 if "appender" not in roles or not hasattr(cls, roles["appender"]):
918 raise sa_exc.ArgumentError(
919 "Type %s must elect an appender method to be "
920 "a collection class" % cls.__name__
921 )
922 elif roles["appender"] not in methods and not hasattr(
923 getattr(cls, roles["appender"]), "_sa_instrumented"
924 ):
925 methods[roles["appender"]] = ("fire_append_event", 1, None)
926
927 if "remover" not in roles or not hasattr(cls, roles["remover"]):
928 raise sa_exc.ArgumentError(
929 "Type %s must elect a remover method to be "
930 "a collection class" % cls.__name__
931 )
932 elif roles["remover"] not in methods and not hasattr(
933 getattr(cls, roles["remover"]), "_sa_instrumented"
934 ):
935 methods[roles["remover"]] = ("fire_remove_event", 1, None)
936
937 if "iterator" not in roles or not hasattr(cls, roles["iterator"]):
938 raise sa_exc.ArgumentError(
939 "Type %s must elect an iterator method to be "
940 "a collection class" % cls.__name__
941 )
942
943
944def _set_collection_attributes(cls, roles, methods):

Callers 1

_instrument_classFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected