Skip to content

Commit

Permalink
Avoid accidental creation of multiple fileproxies (#22)
Browse files Browse the repository at this point in the history
Add the fileproxy on top of standard stream only if one was not already added.
  • Loading branch information
ssbarnea authored Dec 19, 2020
1 parent 600c070 commit b9cbd9f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/enrich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def __init__(self, *args: str, redirect: bool = True, **kwargs: Any) -> None:
self.extended = True

if self.redirect:
sys.stdout = FileProxy(self, sys.stdout) # type: ignore
sys.stderr = FileProxy(self, sys.stderr) # type: ignore
if not hasattr(sys.stdout, "rich_proxied_file"):
sys.stdout = FileProxy(self, sys.stdout) # type: ignore
if not hasattr(sys.stderr, "rich_proxied_file"):
sys.stderr = FileProxy(self, sys.stderr) # type: ignore

# https://github.com/python/mypy/issues/4441
def print(self, *args, **kwargs) -> None: # type: ignore
Expand Down

0 comments on commit b9cbd9f

Please sign in to comment.