Skip to content

Commit 27af53e

Browse files
authored
lib/logging: Set handlers as set instead of list
Handlers is currently initialized as empty list. The operation most per formed is __contains__. Set performs faster for this and ordering of handler is not a concern. Hence replace the list initialization with set.
1 parent 359389e commit 27af53e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Lib/logging/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ def __init__(self, name, level=NOTSET):
14831483
self.level = _checkLevel(level)
14841484
self.parent = None
14851485
self.propagate = True
1486-
self.handlers = []
1486+
self.handlers = set()
14871487
self.disabled = False
14881488
self._cache = {}
14891489

@@ -1685,7 +1685,7 @@ def addHandler(self, hdlr):
16851685
"""
16861686
with _lock:
16871687
if not (hdlr in self.handlers):
1688-
self.handlers.append(hdlr)
1688+
self.handlers.add(hdlr)
16891689

16901690
def removeHandler(self, hdlr):
16911691
"""

0 commit comments

Comments
 (0)