Skip to content

Commit 8793f53

Browse files
committed
utils: Move and reuse apply_all
1 parent d63e988 commit 8793f53

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

Orange/widgets/utils/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import inspect
22
import sys
3+
from collections import deque
4+
from typing import TypeVar, Deque, Callable, Any, Iterable
35

46
from AnyQt.QtCore import QObject
57

@@ -77,3 +79,14 @@ def mypredicate(x):
7779
else:
7880
mypredicate = predicate
7981
return inspect.getmembers(obj, mypredicate)
82+
83+
84+
85+
_T1 = TypeVar("_T1")
86+
87+
88+
def apply_all(seq, op):
89+
# type: (Iterable[_T1], Callable[[_T1], Any]) -> None
90+
"""Apply `op` on all elements of `seq`."""
91+
# from itertools recipes `consume`
92+
deque(map(op, seq), maxlen=0)

Orange/widgets/utils/graphicstextlist.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
QGraphicsWidget, QSizePolicy, QGraphicsItemGroup, QGraphicsSimpleTextItem,
88
QGraphicsItem, QGraphicsScene, QGraphicsSceneResizeEvent
99
)
10+
from . import apply_all
1011
from .graphicslayoutitem import scaled
1112

1213
__all__ = ["TextListWidget"]
1314

1415

15-
def apply_all(iter, op):
16-
for el in iter: op(el)
17-
18-
1916
class TextListWidget(QGraphicsWidget):
2017
"""
2118
A linear text list widget.

Orange/widgets/visualize/utils/heatmap.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import math
22
import enum
3-
from collections import deque
43
from itertools import chain, zip_longest
54

65
from typing import (
7-
Optional, List, NamedTuple, Iterable, Sequence, Tuple, Dict, TypeVar,
8-
Callable, Any, Deque, Union,
6+
Optional, List, NamedTuple, Sequence, Tuple, Dict, Union,
97
)
108

119
import numpy as np
@@ -24,6 +22,7 @@
2422

2523
from Orange.clustering import hierarchical
2624
from Orange.clustering.hierarchical import Tree
25+
from Orange.widgets.utils import apply_all
2726
from Orange.widgets.utils.colorpalettes import DefaultContinuousPalette
2827
from Orange.widgets.utils.graphicslayoutitem import SimpleLayoutItem, scaled
2928
from Orange.widgets.utils.graphicspixmapwidget import GraphicsPixmapWidget
@@ -33,16 +32,6 @@
3332
from Orange.widgets.utils.dendrogram import DendrogramWidget
3433

3534

36-
_T1 = TypeVar("_T1")
37-
38-
39-
def apply_all(seq, op):
40-
# type: (Iterable[_T1], Callable[[_T1], Any]) -> None
41-
"""Apply `op` on all elements of `seq`."""
42-
d = deque(maxlen=0) # type: Deque[_T1]
43-
d.extend(map(op, seq))
44-
45-
4635
def leaf_indices(tree: Tree) -> Sequence[int]:
4736
return [leaf.value.index for leaf in hierarchical.leaves(tree)]
4837

0 commit comments

Comments
 (0)