From: Semyon Pupkov Date: Sat, 11 May 2024 08:19:56 +0000 (+0500) Subject: Optimize has_intersection func X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b38f460b49f06bd5be9b6d52cb3a5fbda1e644b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Optimize has_intersection func --- diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 3d092a0223..f5edf275f5 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -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):