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
refactor: add type hints in version_scanner.py #1581
Conversation
e5e30c1
to
3c716e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untyped:
cve-bin-tool/cve_bin_tool/version_scanner.py
Line 358 in 3c716e5
results = [dict()] |
I don't understand why it has different values in two
if
branches...
score=0, | ||
should_extract: bool = False, | ||
exclude_folders: list[str] = [], | ||
checkers: dict[str, type[Checker]] | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it type[Checker]
and not just Checker
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because its the Checker
subclass itself (uninstantiated) of type CheckerMetaClass
.
cve-bin-tool/cve_bin_tool/version_scanner.py
Lines 353 to 354 in 3c716e5
for (dummy_checker_name, checker) in self.checkers.items(): | |
checker = checker() |
cve-bin-tool/cve_bin_tool/version_scanner.py Lines 348 to 354 in ab07fb9
Tried to remove it, long tests for |
cve_bin_tool/version_scanner.py
Outdated
@@ -33,15 +36,16 @@ class VersionScanner: | |||
""" "Scans files for CVEs using CVE checkers""" | |||
|
|||
CHECKER_ENTRYPOINT = "cve_bin_tool.checker" | |||
Infogen = Iterator[Tuple[Union[ProductInfo, None], str]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very self explanatory. It needs documentation, or perhaps we need some appropriately named custom types to make this clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make it a custom type like ProductInfo
, hope that makes it clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might want to do some additional refinement with custom types, but this looks good enough to merge now. Thank you!
part of #1539