Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hinting for reduce code #433

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions grizzly/common/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ def __init__(
# TODO: make SigInfo dataclass?
self.signature_info: Dict[str, Union[bool, str]] = {}
self.successes = 0
self.current_strategy_idx = None
self.current_strategy_idx: Optional[int] = None
self._testcase_size_cb = testcase_size_cb
self.crash_id = crash_id
self.finished_steps: List[ReductionStep] = []
Expand All @@ -886,7 +886,7 @@ def __init__(
self.tool = tool
self._current_size: Optional[int] = None
# this holds results from Reporter.submit()
self.last_reports = []
self.last_reports: List[str] = []

# prepare database
if self._db_file:
Expand Down
17 changes: 9 additions & 8 deletions grizzly/reduce/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""CLI argument parsing for Grizzly reduction.
"""
from argparse import Namespace
from logging import getLogger
from pathlib import Path

Expand All @@ -19,7 +20,7 @@ class ReduceCommonArgs(ReplayCommonArgs):
Takes all arguments defined for `grizzly.replay`, and a few specific to reduction.
"""

def __init__(self):
def __init__(self) -> None:
"""Initialize argument parser."""
super().__init__()

Expand Down Expand Up @@ -52,11 +53,11 @@ def __init__(self):
help="One or more strategies. (default: %(default)s)",
)

def sanity_check(self, args):
def sanity_check(self, args: Namespace) -> None:
"""Sanity check reducer args.

Arguments:
args (argparse.Namespace): Result from `parse_args()`.
args: Result from `parse_args()`.

Raises:
SystemExit: on error, `ArgumentParser.error()` is called, which will exit.
Expand Down Expand Up @@ -86,7 +87,7 @@ def sanity_check(self, args):

class ReduceArgs(ReduceCommonArgs):
# NOTE: If updated changes may also need to be added to ReplayArgs
def __init__(self):
def __init__(self) -> None:
super().__init__()
self.parser.add_argument("input", type=Path, nargs="+", help=LOCAL_INPUT_HELP)

Expand All @@ -97,7 +98,7 @@ def __init__(self):
" automatically determined.",
)

def sanity_check(self, args):
def sanity_check(self, args: Namespace) -> None:
super().sanity_check(args)

for test in args.input:
Expand All @@ -109,7 +110,7 @@ def sanity_check(self, args):


class ReduceFuzzManagerIDArgs(ReduceCommonArgs):
def __init__(self):
def __init__(self) -> None:
"""Initialize argument parser."""
super().__init__()
self.parser.add_argument("input", type=int, help="FuzzManager ID to reduce")
Expand All @@ -135,7 +136,7 @@ def __init__(self):
"0 == oldest, n-1 == most recent (default: run all testcases)",
)

def sanity_check(self, args):
def sanity_check(self, args: Namespace) -> None:
super().sanity_check(args)

if args.no_harness and len(args.test_index) > 1:
Expand All @@ -145,7 +146,7 @@ def sanity_check(self, args):


class ReduceFuzzManagerIDQualityArgs(ReduceFuzzManagerIDArgs):
def __init__(self):
def __init__(self) -> None:
"""Initialize argument parser."""
super().__init__()
self.parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion grizzly/reduce/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def reporter_sequential_strftime(mocker):
prefix = mocker.patch("grizzly.common.report.strftime")

def report_prefix(_):
return f"{prefix.call_count:0>4d}"
return f"{prefix.call_count:04d}"

prefix.side_effect = report_prefix
Loading
Loading