From a730b9b66a666d7263c4dd43706eb566851e5726 Mon Sep 17 00:00:00 2001 From: Antonin RAFFIN Date: Fri, 21 Jul 2023 07:02:38 +0200 Subject: [PATCH] Relax logger check for Windows (#1615) * Relax logger check for Windows * Update tests --- docs/misc/changelog.rst | 3 ++- stable_baselines3/common/logger.py | 6 ++++-- stable_baselines3/version.txt | 2 +- tests/test_logger.py | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index eaa761d..4ecf61b 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -4,7 +4,7 @@ Changelog ========== -Release 2.1.0a1 (WIP) +Release 2.1.0a2 (WIP) -------------------------- Breaking Changes: @@ -25,6 +25,7 @@ New Features: Bug Fixes: ^^^^^^^^^^ +- Relaxed check in logger, that was causing issue on Windows with colorama Deprecations: ^^^^^^^^^^^^^ diff --git a/stable_baselines3/common/logger.py b/stable_baselines3/common/logger.py index 4d0d346..3955131 100644 --- a/stable_baselines3/common/logger.py +++ b/stable_baselines3/common/logger.py @@ -164,8 +164,10 @@ class HumanOutputFormat(KVWriter, SeqWriter): if isinstance(filename_or_file, str): self.file = open(filename_or_file, "w") self.own_file = True - elif isinstance(filename_or_file, TextIOBase): - self.file = filename_or_file + elif isinstance(filename_or_file, TextIOBase) or hasattr(filename_or_file, "write"): + # Note: in theory `TextIOBase` check should be sufficient, + # in practice, libraries don't always inherit from it, see GH#1598 + self.file = filename_or_file # type: ignore[assignment] self.own_file = False else: raise ValueError(f"Expected file or str, got {filename_or_file}") diff --git a/stable_baselines3/version.txt b/stable_baselines3/version.txt index 0e4065c..55c98c9 100644 --- a/stable_baselines3/version.txt +++ b/stable_baselines3/version.txt @@ -1 +1 @@ -2.1.0a1 +2.1.0a2 diff --git a/tests/test_logger.py b/tests/test_logger.py index 9d275a2..05bf196 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -437,8 +437,9 @@ def test_ep_buffers_stats_window_size(algo, stats_window_size): assert model.ep_success_buffer.maxlen == stats_window_size -def test_human_output_format_custom_test_io(): - class DummyTextIO(TextIOBase): +@pytest.mark.parametrize("base_class", [object, TextIOBase]) +def test_human_output_format_custom_test_io(base_class): + class DummyTextIO(base_class): def __init__(self) -> None: super().__init__() self.lines = [[]]