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

Complete typing for logger_utils.py #4134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions manim/_config/logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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
Expand Down Expand Up @@ -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,
)

Expand All @@ -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
Expand All @@ -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}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not typing.Dict ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong here, but I thought there is no difference between typing.Dict and dict anymore, since PEP 585 introduced generic type support for these built-in types.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I was just thinking that you wanted to use typing everywhere ;-)


theme["log.width"] = None if theme["log.width"] == "-1" else int(theme["log.width"])
theme["log.height"] = (
Expand Down Expand Up @@ -188,8 +188,11 @@ def format(self, record: logging.LogRecord) -> str:
"""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,
Expand Down
Loading