MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _setup_canned_roles

Function _setup_canned_roles

lib/sqlalchemy/orm/collections.py:887–909  ·  view source on GitHub ↗

see if this class has "canned" roles based on a known collection type (dict, set, list). Apply those roles as needed to the "roles" dictionary, and also prepare "decorator" methods

(cls, roles, methods)

Source from the content-addressed store, hash-verified

885
886
887def _setup_canned_roles(cls, roles, methods):
888 """see if this class has "canned" roles based on a known
889 collection type (dict, set, list). Apply those roles
890 as needed to the "roles" dictionary, and also
891 prepare "decorator" methods
892
893 """
894 collection_type = util.duck_type_collection(cls)
895 if collection_type in __interfaces:
896 assert collection_type is not None
897 canned_roles, decorators = __interfaces[collection_type]
898 for role, name in canned_roles.items():
899 roles.setdefault(role, name)
900
901 # apply ABC auto-decoration to methods that need it
902 for method, decorator in decorators.items():
903 fn = getattr(cls, method, None)
904 if (
905 fn
906 and method not in methods
907 and not hasattr(fn, "_sa_instrumented")
908 ):
909 setattr(cls, method, decorator(fn))
910
911
912def _assert_required_roles(cls, roles, methods):

Callers 1

_instrument_classFunction · 0.85

Calls 3

decoratorFunction · 0.85
itemsMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected