File tree Expand file tree Collapse file tree 1 file changed +16
-14
lines changed Expand file tree Collapse file tree 1 file changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -262,17 +262,19 @@ def find_by(self, **conditions: Any) -> T | None:
262262 The first record matching the conditions, or `None` if no match is found.
263263 """
264264 results = self .fetch ()
265- for item in results :
266- if obj_has_attrs (item , conditions ):
267- return item
268- return None
269-
270-
271- def obj_has_attrs (obj : ReadOnlyDict , attrs : dict [str , Any ]) -> bool :
272- for attr_key , attr_val in attrs .items ():
273- if not hasattr (obj , attr_key ):
274- return False
275- obj_val = getattr (obj , attr_key )
276- if obj_val != attr_val :
277- return False
278- return True
265+
266+ conditions_items = conditions .items ()
267+
268+ # Get the first item of the generator that matches the conditions
269+ # If no item is found, return None
270+ return next (
271+ (
272+ # Return result
273+ result
274+ # Iterate through `results` generator
275+ for result in results
276+ # If all `conditions`'s key/values are found in `result`'s key/values...
277+ if result .items () >= conditions_items
278+ ),
279+ None ,
280+ )
You can’t perform that action at this time.
0 commit comments