From 38ae595e1f4f57dfcd2484375871bcf349a76430 Mon Sep 17 00:00:00 2001 From: Brad Beattie <79596181+bbeattie-phxlabs@users.noreply.github.com> Date: Mon, 21 Mar 2022 16:22:32 -0700 Subject: [PATCH 1/2] Handle monkey-patched stdout In some Python environments (e.g. Maya 2022's mayapy.exe), sys.stdout has been monkey-patched to something other than the expected stdout. As such, it doesn't actually have an `isatty` method and raises an AttributeError in response. --- src/structlog/_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structlog/_config.py b/src/structlog/_config.py index 536494b1..f0d60744 100644 --- a/src/structlog/_config.py +++ b/src/structlog/_config.py @@ -40,7 +40,7 @@ set_exc_info, TimeStamper(fmt="%Y-%m-%d %H:%M.%S", utc=False), ConsoleRenderer( - colors=_use_colors and sys.stdout is not None and sys.stdout.isatty() + colors=_use_colors and sys.stdout is not None and hasattr(sys.stdout, "isatty") and sys.stdout.isatty() ), ] _BUILTIN_DEFAULT_CONTEXT_CLASS = cast(Type[Context], dict) From 625c81a870891caa2c3fd63afc85a0f0d9a68fdd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 21 Mar 2022 23:25:21 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/structlog/_config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/structlog/_config.py b/src/structlog/_config.py index f0d60744..2f072c72 100644 --- a/src/structlog/_config.py +++ b/src/structlog/_config.py @@ -40,7 +40,10 @@ set_exc_info, TimeStamper(fmt="%Y-%m-%d %H:%M.%S", utc=False), ConsoleRenderer( - colors=_use_colors and sys.stdout is not None and hasattr(sys.stdout, "isatty") and sys.stdout.isatty() + colors=_use_colors + and sys.stdout is not None + and hasattr(sys.stdout, "isatty") + and sys.stdout.isatty() ), ] _BUILTIN_DEFAULT_CONTEXT_CLASS = cast(Type[Context], dict)