MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _union_other

Method _union_other

lib/sqlalchemy/util/_immutabledict_cy.py:164–216  ·  view source on GitHub ↗
(self, others: tuple)

Source from the content-addressed store, hash-verified

162 @cython.cfunc
163 @cython.inline
164 def _union_other(self, others: tuple) -> immutabledict:
165 size = len(others)
166 if size == 0:
167 return self
168
169 # only_one == immutabledict : we found exactly one immutabledict that
170 # has contents; no other dict / immutabledict has any contents
171 #
172 # only_one is None : we found more than one dict / immutabledict that
173 # has contents
174 #
175 # only_one is False : we've found nothing that is not an empty
176 # immutabledict
177 only_one: immutabledict | None | Literal[False]
178
179 if self:
180 self_is_empty = False
181 only_one = self
182 else:
183 only_one = False
184 self_is_empty = True
185
186 for i in range(size):
187 d = others[i]
188 if not d:
189 continue
190
191 if only_one is False and isinstance(d, immutabledict):
192 only_one = d
193 else:
194 only_one = None
195 break
196
197 if only_one is False:
198 return self
199 elif only_one is not None:
200 return only_one
201
202 result: immutabledict = immutabledict()
203 if not self_is_empty:
204 PyDict_Update(result, self)
205
206 for i in range(size):
207 d = others[i]
208 if not d:
209 continue
210 if isinstance(d, dict):
211 # c version of PyDict_Update supports only dicts
212 PyDict_Update(result, d)
213 else:
214 dict.update(result, d)
215
216 return result
217
218 def copy(self) -> Self:
219 return self

Callers 2

unionMethod · 0.95
merge_withMethod · 0.95

Calls 2

immutabledictClass · 0.70
updateMethod · 0.45

Tested by

no test coverage detected