Skip to content

Commit

Permalink
Issue #491 - Move logger globals for Python bug
Browse files Browse the repository at this point in the history
Shift the `log.py` logger globals to the beginning of the file to avoid
a Python bug that causes spurious "annotated name can't be global"
errors when mypy lints the files.

See here for the issue report:
https://bugs.python.org/issue34939

Clarification on the ticket marks this as a bug and a fix was added.
This avoids the error in Python 3.7.
  • Loading branch information
MJJoyce committed Jan 24, 2023
1 parent 63720ff commit 74f9778
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ait/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
logging.addLevelName(COMMAND, "COMMAND")
logging.addLevelName(PROGRAM, "PROGRAM")

logger = None
crit: Optional[Callable[[str], str]] = None
debug: Optional[Callable[[str], str]] = None
error: Optional[Callable[[str], str]] = None
info: Optional[Callable[[str], str]] = None
warn: Optional[Callable[[str], str]] = None


class LogFormatter(logging.Formatter):
"""LogFormatter
Expand Down Expand Up @@ -313,14 +320,4 @@ def notice(*args, **kwargs):
logger.log(NOTICE, *args, **kwargs)


# These are "guaranteed" at runtime to be not-None. Marking this as
# type `Any` addresses mypy issues where log calls are marked as
# "None" being not callable.
logger = None
crit: Optional[Callable[[str], str]] = None
debug: Optional[Callable[[str], str]] = None
error: Optional[Callable[[str], str]] = None
info: Optional[Callable[[str], str]] = None
warn: Optional[Callable[[str], str]] = None

init()

0 comments on commit 74f9778

Please sign in to comment.