Skip to content

fix colorlog compatibility problem#4406

Merged
keisuke-umezawa merged 4 commits intooptuna:masterfrom
gen740:fix_colorlog_compatibility_problem
Feb 14, 2023
Merged

fix colorlog compatibility problem#4406
keisuke-umezawa merged 4 commits intooptuna:masterfrom
gen740:fix_colorlog_compatibility_problem

Conversation

@gen740
Copy link
Copy Markdown
Member

@gen740 gen740 commented Feb 8, 2023

Motivation

Fix #4403.

Description of the changes

Use logging.Formatter if _color_supported returns True.

@gen740 gen740 force-pushed the fix_colorlog_compatibility_problem branch from 1d6c760 to 4ff5fd4 Compare February 8, 2023 05:01
@gen740 gen740 added the bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself. label Feb 8, 2023
Copy link
Copy Markdown
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

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

Thank you for your PR. I have two comments.



def create_default_formatter() -> colorlog.ColoredFormatter:
def create_default_formatter() -> Union[Formatter, colorlog.ColoredFormatter]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

colorlog.ColoredFormatter extends logging.Formatter, and I guess the return type can be Formatter.

Suggested change
def create_default_formatter() -> Union[Formatter, colorlog.ColoredFormatter]:
def create_default_formatter() -> Formatter:

And, the returned value is pass to logging.Handler.setFormatter, and it expects logging.Formatter. So, I don't think it does not depend on the colorlog version.

_default_handler.setFormatter(create_default_formatter())

@toshihikoyanase
Copy link
Copy Markdown
Member

@contramundum53 Could you review this PR as an author of #4403?

@contramundum53
Copy link
Copy Markdown
Member

I confirmed that it works with colorlog 4.8. Thanks for the PR!

gen740 and others added 2 commits February 11, 2023 22:59
Co-authored-by: Toshihiko Yanase <toshihiko.yanase@gmail.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #4406 (e0c5d7a) into master (b614903) will decrease coverage by 0.02%.
The diff coverage is 80.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #4406      +/-   ##
==========================================
- Coverage   90.41%   90.40%   -0.02%     
==========================================
  Files         172      172              
  Lines       13675    13679       +4     
==========================================
+ Hits        12364    12366       +2     
- Misses       1311     1313       +2     
Impacted Files Coverage Δ
optuna/samplers/_cmaes.py 98.25% <77.77%> (-0.87%) ⬇️
optuna/logging.py 94.52% <83.33%> (-1.14%) ⬇️
optuna/integration/pytorch_distributed.py 88.46% <0.00%> (-0.06%) ⬇️
optuna/integration/pytorch_lightning.py 0.00% <0.00%> (ø)
optuna/integration/sklearn.py 97.03% <0.00%> (+0.27%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@contramundum53
Copy link
Copy Markdown
Member

@keisuke-umezawa Could you review this PR?

Co-authored-by: Toshihiko Yanase <toshihiko.yanase@gmail.com>
Copy link
Copy Markdown
Member

@keisuke-umezawa keisuke-umezawa left a comment

Choose a reason for hiding this comment

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

LGTM! I confirmed it works on my local env for both situations. Thank you for your quick fix.

@keisuke-umezawa keisuke-umezawa merged commit 5e96441 into optuna:master Feb 14, 2023
@keisuke-umezawa keisuke-umezawa added this to the v3.2.0 milestone Feb 14, 2023
@toshihikoyanase toshihikoyanase removed their assignment Feb 14, 2023
@gen740 gen740 deleted the fix_colorlog_compatibility_problem branch February 21, 2023 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#4376 breaks compatibility with old colorlog

5 participants