Skip to content

Commit 6892ad7

Browse files
committed
Add more type annotations
1 parent cb6961d commit 6892ad7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

px/px_process.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from typing import Text # NOQA
2323
from typing import Optional # NOQA
2424
from typing import List # NOQA
25+
from typing import Iterable # NOQA
2526
from six import text_type # NOQA
2627

2728

@@ -321,8 +322,11 @@ def ps_line_to_process(ps_line, now):
321322

322323

323324
def create_kernel_process(now):
324-
# Fake a process 0, this one isn't returned by ps. More info about PID 0:
325-
# https://en.wikipedia.org/wiki/Process_identifier
325+
# type: (datetime.datetime) -> PxProcess
326+
"""
327+
Fake a process 0, this one isn't returned by ps. More info about PID 0:
328+
https://en.wikipedia.org/wiki/Process_identifier
329+
"""
326330
process_builder = PxProcessBuilder()
327331
process_builder.pid = 0
328332
process_builder.ppid = None
@@ -368,8 +372,10 @@ def resolve_links(processes, now):
368372

369373

370374
def remove_process_and_descendants(processes, pid):
375+
# type: (Dict[int, PxProcess], int) -> None
371376
process = processes[pid]
372-
process.parent.children.remove(process)
377+
if process.parent is not None:
378+
process.parent.children.remove(process)
373379
toexclude = [process]
374380
while toexclude:
375381
process = toexclude.pop()
@@ -394,11 +400,13 @@ def get_all():
394400

395401

396402
def order_best_last(processes):
403+
# type: (Iterable[PxProcess]) -> List[PxProcess]
397404
"""Returns process list ordered with the most interesting one last"""
398405
return sorted(processes, key=operator.attrgetter('score', 'cmdline'))
399406

400407

401408
def order_best_first(processes):
409+
# type: (Iterable[PxProcess]) -> List[PxProcess]
402410
"""Returns process list ordered with the most interesting one first"""
403411
ordered = sorted(processes, key=operator.attrgetter('cmdline'))
404412
ordered = sorted(ordered, key=operator.attrgetter('score'), reverse=True)

tests/testutils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def create_ipc_map(pid, all_files, is_root=False):
9797

9898

9999
def fake_callchain(*args):
100+
# type: (*str) -> px_process.PxProcess
100101
procs = []
101102
for arg in args:
102103
procs.append(create_process(commandline=arg))

0 commit comments

Comments
 (0)