Skip to content

Commit 8c5a5ff

Browse files
authored
refactor: improve warning suppression performance by using sets (#1932)
* feat(performance): improve warning suppression lookup by using set * fix: initialize _no_warn_slugs as a empty set
1 parent 97ce68c commit 8c5a5ff

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

coverage/control.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def __init__( # pylint: disable=too-many-arguments
258258
self._warn_no_data = True
259259
self._warn_unimported_source = True
260260
self._warn_preimported_source = check_preimported
261-
self._no_warn_slugs: list[str] = []
261+
self._no_warn_slugs: set[str] = set()
262262
self._messages = messages
263263

264264
# A record of all the warnings that have been issued.
@@ -438,7 +438,7 @@ def _warn(self, msg: str, slug: str | None = None, once: bool = False) -> None:
438438
439439
"""
440440
if not self._no_warn_slugs:
441-
self._no_warn_slugs = list(self.config.disable_warnings)
441+
self._no_warn_slugs = set(self.config.disable_warnings)
442442

443443
if slug in self._no_warn_slugs:
444444
# Don't issue the warning
@@ -453,7 +453,7 @@ def _warn(self, msg: str, slug: str | None = None, once: bool = False) -> None:
453453

454454
if once:
455455
assert slug is not None
456-
self._no_warn_slugs.append(slug)
456+
self._no_warn_slugs.add(slug)
457457

458458
def _message(self, msg: str) -> None:
459459
"""Write a message to the user, if configured to do so."""

0 commit comments

Comments
 (0)