Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Aug 26, 2019
1 parent e471065 commit 4454bc3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/stdio_mgr/stdio_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,21 @@ class SafeCloseTeeStdin(_SafeCloseIOBase, TeeStdin):


class TupleContextManager(tuple, AbstractContextManager):
pass
"""Base for context managers that are also a tuple."""
# This is needed to establish a workable MRO.


class StdioTuple(TupleContextManager):
"""Tuple of stdin, stdout and stderr streams."""
"""Tuple context manager of stdin, stdout and stderr streams."""

def __new__(cls, iterable):
"""Instantiate new tuple from iterable constaining three TextIOBase."""
items = list(iterable)
assert len(items) == 3
assert len(items) == 3 # noqa: S101
# pytest and colorama break this assertion when applied to the sys.foo
# when they replace them with custom objects, and probably many other
# similar tools do the same
# assert all(isinstance(item, TextIOBase) for item in items), \
# list(type(item) for item in items)
# assert all(isinstance(item, TextIOBase) for item in items) # noqa: E800

return super(StdioTuple, cls).__new__(cls, items)

Expand Down Expand Up @@ -341,6 +342,7 @@ class FakeStdioTuple(StdioTuple, _MultiCloseContextManager):
"""

def __new__(cls, in_str="", close=True):
"""Instantiate new tuple of fake stdin, stdout and stderr."""
if close:
out_cls = SafeCloseRandomTextIO
in_cls = SafeCloseTeeStdin
Expand All @@ -359,6 +361,7 @@ class CurrentSysIoStreams(StdioTuple):
"""Tuple of current stdin, stdout and stderr streams."""

def __new__(cls):
"""Instantiate new tuple of current sys.stdin, sys.stdout and sys.stderr."""
items = [sys.stdin, sys.stdout, sys.stderr]
return super(CurrentSysIoStreams, cls).__new__(cls, items)

Expand All @@ -377,7 +380,7 @@ class StdioManager(_MultiCloseContextManager):
"""

def __new__(cls, in_str="", close=True, streams=None):
"""Instantiate new context manager that emulates namedtuple."""
"""Instantiate new context manager for streams."""
if not streams:
streams = FakeStdioTuple(in_str, close)

Expand Down

0 comments on commit 4454bc3

Please sign in to comment.