From 88bc421f887afe1f73736b269099ab088941249a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@ericsson.com> Date: Sat, 31 Aug 2024 17:04:55 +0200 Subject: [PATCH] v2.25.5 --- CHANGELOG.md | 1 + satella/__init__.py | 2 +- satella/coding/structures/heaps/base.py | 25 +++++++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74314ef9..3f97df83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v2.25.5 * slight optimization for Heap.push_many +* bugfix for Heap.push and a deprecation # v2.25.4 diff --git a/satella/__init__.py b/satella/__init__.py index 3406069a..55bf16c7 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.25.5a2' +__version__ = '2.25.5' diff --git a/satella/coding/structures/heaps/base.py b/satella/coding/structures/heaps/base.py index 6d25f107..41c5da12 100644 --- a/satella/coding/structures/heaps/base.py +++ b/satella/coding/structures/heaps/base.py @@ -7,14 +7,6 @@ from satella.coding.decorators.decorators import wraps from satella.coding.typing import T, Predicate -def _extras_to_one(fun): - @wraps(fun) - def inner(self, a, *args, **kwargs): - return fun(self, ((a,) + args) if len(args) > 0 else a, **kwargs) - - return inner - - class Heap(collections.UserList, tp.Generic[T]): """ Sane heap as object - not like heapq. @@ -52,8 +44,7 @@ class Heap(collections.UserList, tp.Generic[T]): heapq.heapify(self.data) return item - @_extras_to_one - def push(self, item: T) -> None: + def push(self, item: T, *args) -> None: """ Use it like: @@ -62,7 +53,14 @@ class Heap(collections.UserList, tp.Generic[T]): or: >>> heap.push(4, myobject) + + However this syntax is + + .. deprecated:: 2.25.5 + It's not legible """ + if args: + item = (item, *args) heapq.heappush(self.data, item) def __deepcopy__(self, memo={}) -> 'Heap': @@ -147,6 +145,13 @@ class SetHeap(Heap): #notthreadsafe """ + def push_many(self, items: tp.Iterable[T]) -> None: + """ + Not that much faster than inserting anything by hand + """ + for item in items: + self.push(item) + def __init__(self, from_list: tp.Optional[tp.Iterable[T]] = None): super().__init__(from_list=from_list) self.set = set(self.data) -- GitLab