Skip to content

Commit 429f02c

Browse files
chore(profiling): add type annotations to test_threading.py (#14872)
[PROF-12734] ## Description This PR continues type-annotating the Lock profiler code by annotating the `test_threading.py` file. ## Testing * `$ ./scripts/ddtest riot -v run --pass-env ee8eca7 -- tests/profiling_v2/collector/test_threading.py` * CI ## Risks none [PROF-12734]: https://datadoghq.atlassian.net/browse/PROF-12734?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Taegyun Kim <[email protected]>
1 parent 5b375e1 commit 429f02c

File tree

2 files changed

+184
-167
lines changed

2 files changed

+184
-167
lines changed

tests/profiling/collector/lock_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
from collections import namedtuple
22
import sys
3+
from typing import Dict
34

45

56
LineNo = namedtuple("LineNo", ["create", "acquire", "release"])
6-
lock_locs = {}
7+
lock_locs: Dict[str, LineNo] = {}
78
loc_type_map = {
89
"!CREATE!": "create",
910
"!ACQUIRE!": "acquire",
1011
"!RELEASE!": "release",
1112
}
1213

1314

14-
def get_lock_locations(path: str):
15+
def get_lock_locations(path: str) -> None:
1516
"""
1617
The lock profiler is capable of determining where locks are created and used. In order to test this behavior, line
1718
numbers are compared in several tests. However, since it's cumbersome to write the tests in any way except
@@ -34,12 +35,12 @@ def get_lock_locations(path: str):
3435
lock_locs[lock_name] = lock_locs[lock_name]._replace(**{field: lineno})
3536

3637

37-
def get_lock_linenos(name, with_stmt=False):
38+
def get_lock_linenos(name, with_stmt=False) -> LineNo:
3839
linenos = lock_locs.get(name, LineNo(0, 0, 0))
3940
if with_stmt and sys.version_info < (3, 10):
4041
linenos = linenos._replace(release=linenos.release + 1)
4142
return linenos
4243

4344

44-
def init_linenos(path):
45+
def init_linenos(path) -> None:
4546
get_lock_locations(path)

0 commit comments

Comments
 (0)