Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Complete typing for logger_utils.py (#4134)

F. Muenkelfdc496c2112a
diff --git a/manim/_config/logger_utils.py b/manim/_config/logger_utils.py
index 9205635ee..427cf41ca 100644
--- a/manim/_config/logger_utils.py
+++ b/manim/_config/logger_utils.py
@@ -16,7 +16,7 @@ import configparser
import copy
import json
import logging
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Any
from rich import color, errors
from rich import print as printf
@@ -91,7 +91,7 @@ def make_logger(
# set the rich handler
rich_handler = RichHandler(
console=console,
- show_time=parser.getboolean("log_timestamps"),
+ show_time=parser.getboolean("log_timestamps", fallback=False),
keywords=HIGHLIGHTED_KEYWORDS,
)
@@ -108,7 +108,7 @@ def make_logger(
return logger, console, error_console
-def parse_theme(parser: configparser.SectionProxy) -> Theme:
+def parse_theme(parser: configparser.SectionProxy) -> Theme | None:
"""Configure the rich style of logger and console output.
Parameters
@@ -126,7 +126,7 @@ def parse_theme(parser: configparser.SectionProxy) -> Theme:
:func:`make_logger`.
"""
- theme = {key.replace("_", "."): parser[key] for key in parser}
+ theme: dict[str, Any] = {key.replace("_", "."): parser[key] for key in parser}
theme["log.width"] = None if theme["log.width"] == "-1" else int(theme["log.width"])
theme["log.height"] = (
@@ -188,8 +188,11 @@ class JSONFormatter(logging.Formatter):
"""Format the record in a custom JSON format."""
record_c = copy.deepcopy(record)
if record_c.args:
- for arg in record_c.args:
- record_c.args[arg] = "<>"
+ if isinstance(record_c.args, dict):
+ for arg in record_c.args:
+ record_c.args[arg] = "<>"
+ else:
+ record_c.args = ("<>",) * len(record_c.args)
return json.dumps(
{
"levelname": record_c.levelname,
diff --git a/mypy.ini b/mypy.ini
index 80571869b..4b5f71850 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -52,6 +52,9 @@ warn_return_any = True
ignore_errors = True
disable_error_code = return-value
+[mypy-manim._config.logger_utils]
+ignore_errors = False
+
[mypy-manim.animation.*]
ignore_errors = True