Skip to content

Commit 0d76f24

Browse files
committed
Add types to NullLock and rename to NullRLock
1 parent 272f2e6 commit 0d76f24

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

tools/wptrunner/wptrunner/wptlogging.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import logging
44
from threading import Thread
5+
from types import TracebackType
6+
from typing import Optional, Type
57

68
from mozlog import commandline, stdadapter, set_default_logger
79
from mozlog.structuredlog import StructuredLogger, log_levels
@@ -77,7 +79,7 @@ def __init__(self, queue, level=logging.NOTSET):
7779

7880
def createLock(self):
7981
# The queue provides its own locking
80-
self.lock = NullLock()
82+
self.lock = NullRLock()
8183

8284
def emit(self, record):
8385
msg = self.format(record)
@@ -91,18 +93,22 @@ def emit(self, record):
9193

9294

9395

94-
class NullLock:
95-
def acquire(self):
96-
pass
96+
class NullRLock:
97+
"""Implementation of the threading.RLock API that doesn't actually acquire a lock,
98+
for use in cases where there is another mechanism to provide the required
99+
invariants."""
97100

98-
def release(self):
99-
pass
101+
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool:
102+
return True
100103

101-
def __enter__(self):
102-
return self
104+
def release(self) -> None:
105+
return None
103106

104-
def __exit__(self, *args, **kwargs):
105-
pass
107+
def __enter__(self) -> bool:
108+
return True
109+
110+
def __exit__(self, t: Optional[Type[BaseException]], v: Optional[BaseException], tb: Optional[TracebackType]) -> None:
111+
return None
106112

107113

108114
class LogQueueThread(Thread):

0 commit comments

Comments
 (0)