Skip to content

fix: explicitly type LOGGER as logging.Logger in log.py#5711

Closed
sarthak-here wants to merge 3 commits into
ossf:mainfrom
sarthak-here:fix/logger-type-annotation
Closed

fix: explicitly type LOGGER as logging.Logger in log.py#5711
sarthak-here wants to merge 3 commits into
ossf:mainfrom
sarthak-here:fix/logger-type-annotation

Conversation

@sarthak-here

Copy link
Copy Markdown

What this fixes

Closes #2870

LOGGER in cve_bin_tool/log.py had no explicit type annotation, which caused mypy to raise "cve_bin_tool.log.LOGGER is not a valid type".

Why not Optional[logging.Logger]

The two existing PRs (#5665, #5666) annotate LOGGER as Optional[logging.Logger], but logging.getLogger() never returns None — it always returns a Logger instance. Marking it Optional would push unnecessary null-checks to every callsite that imports and uses LOGGER.

The fix

LOGGER: logging.Logger = logging.getLogger(__package__)

A single non-optional annotation that accurately reflects what getLogger() returns.

Testing

$ python -m mypy cve_bin_tool/log.py
Success: no issues found in 1 source file

logging.getLogger() never returns None, so LOGGER should be annotated
as logging.Logger rather than left unannotated or marked Optional.
This resolves the mypy type error without pushing Optional checks
to every callsite that uses LOGGER.

Fixes ossf#2870

Signed-off-by: sarthak-here <sarthak909999@gmail.com>
@sarthak-here
sarthak-here force-pushed the fix/logger-type-annotation branch from 2db8441 to bcfc2bf Compare April 19, 2026 16:53
@sarthak-here

Copy link
Copy Markdown
Author

hey can anyone check it out and see if i can merge it

@sarthak-here
sarthak-here deleted the fix/logger-type-annotation branch April 30, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"cve_bin_tool.log.LOGGER is not a valid type"

1 participant