MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _list_decorators

Function _list_decorators

lib/sqlalchemy/orm/collections.py:1078–1216  ·  view source on GitHub ↗

Tailored instrumentation wrappers for any list-like class.

()

Source from the content-addressed store, hash-verified

1076
1077
1078def _list_decorators() -> Dict[str, Callable[[_FN], _FN]]:
1079 """Tailored instrumentation wrappers for any list-like class."""
1080
1081 def _tidy(fn):
1082 fn._sa_instrumented = True
1083 fn.__doc__ = getattr(list, fn.__name__).__doc__
1084
1085 def append(fn):
1086 def append(self, item, _sa_initiator=None):
1087 item = __set(self, item, _sa_initiator, NO_KEY)
1088 fn(self, item)
1089
1090 _tidy(append)
1091 return append
1092
1093 def remove(fn):
1094 def remove(self, value, _sa_initiator=None):
1095 __del(self, value, _sa_initiator, NO_KEY)
1096 # testlib.pragma exempt:__eq__
1097 fn(self, value)
1098
1099 _tidy(remove)
1100 return remove
1101
1102 def insert(fn):
1103 def insert(self, index, value):
1104 value = __set(self, value, None, index)
1105 fn(self, index, value)
1106
1107 _tidy(insert)
1108 return insert
1109
1110 def __setitem__(fn):
1111 def __setitem__(self, index, value):
1112 if not isinstance(index, slice):
1113 existing = self[index]
1114 if existing is not None:
1115 __del(self, existing, None, index)
1116 value = __set(self, value, None, index)
1117 fn(self, index, value)
1118 else:
1119 # slice assignment requires __delitem__, insert, __len__
1120 step = index.step or 1
1121 start = index.start or 0
1122 if start < 0:
1123 start += len(self)
1124 if index.stop is not None:
1125 stop = index.stop
1126 else:
1127 stop = len(self)
1128 if stop < 0:
1129 stop += len(self)
1130
1131 if step == 1:
1132 if value is self:
1133 return
1134 for i in range(start, stop, step):
1135 if len(self) > start:

Callers 1

collections.pyFile · 0.85

Calls 3

localsFunction · 0.85
copyMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected