]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Optimize has_intersection func
authorSemyon Pupkov <mail@semyonpupkov.com>
Sat, 11 May 2024 08:19:56 +0000 (13:19 +0500)
committerSemyon Pupkov <mail@semyonpupkov.com>
Sat, 11 May 2024 08:19:56 +0000 (13:19 +0500)
lib/sqlalchemy/util/_collections.py

index 3d092a0223ed73232e0b3ca340a7d70fa9bb33eb..f5edf275f5ef5fe91501480949d1802bb291b020 100644 (file)
@@ -401,7 +401,7 @@ def to_list(x: Any, default: Optional[List[Any]] = None) -> List[Any]:
         return list(x)
 
 
-def has_intersection(set_, iterable):
+def has_intersection(set_: Union[Set[Any], FrozenSet[Any]], iterable: Iterable[Any]) -> bool:
     r"""return True if any items of set\_ are present in iterable.
 
     Goes through special effort to ensure __hash__ is not called
@@ -409,7 +409,7 @@ def has_intersection(set_, iterable):
 
     """
     # TODO: optimize, write in C, etc.
-    return bool(set_.intersection([i for i in iterable if i.__hash__]))
+    return any(i in set_ for i in iterable if i.__hash__)
 
 
 def to_set(x):