Skip to content

Commit

Permalink
Handle monkey-patched stdout (#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
bbeattie-phxlabs and pre-commit-ci[bot] authored Mar 22, 2022
1 parent d816d23 commit 3d16e95
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 3d16e95

Please sign in to comment.