Skip to content

Commit

Permalink
Handle monkey-patched stdout (hynek#404)
Browse files Browse the repository at this point in the history
* 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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and said-flwls committed May 10, 2023
1 parent 858c5c8 commit 8806364
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/structlog/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
Expand Down

0 comments on commit 8806364

Please sign in to comment.