Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 5, 2024
1 parent 020f77b commit 45eec92
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/py/pyodide/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
class redirect_stdin(_RedirectStream[Any]):
_stream = "stdin"


class _StdioFile(TextIOBase):
def __init__(self, name: str, encoding: str='utf-8', errors: str='strict'):
def __init__(self, name: str, encoding: str = "utf-8", errors: str = "strict"):
self._name = name
self._encoding = encoding
self._errors = errors
Expand All @@ -60,8 +61,15 @@ def name(self):
def isatty(self):
return True


class _StdOutputFile(_StdioFile):
def __init__(self, write_handler: Callable[[str], int | None], name: str, encoding: str='utf-8', errors: str='strict'):
def __init__(
self,
write_handler: Callable[[str], int | None],
name: str,
encoding: str = "utf-8",
errors: str = "strict",
):
super().__init__(name, encoding, errors)
self._write_handler = write_handler

Expand All @@ -77,13 +85,19 @@ def write(self, s: str) -> int:
# They didn't tell us how much they wrote, assume it was the whole string
return len(s)
return written


class _StdInputFile(_StdioFile):
def __init__(self, read_handler: Callable[[int], str], name: str, encoding: str='utf-8', errors: str='strict'):
def __init__(
self,
read_handler: Callable[[int], str],
name: str,
encoding: str = "utf-8",
errors: str = "strict",
):
super().__init__(name, encoding, errors)
self._read_handler = read_handler
self._buffer = ''
self._buffer = ""

def readable(self) -> bool:
return True
Expand All @@ -96,7 +110,9 @@ def read(self, size: int | None = -1) -> str:
# sys.stdin.readline(None) raises a TypeError
size = -1
if not isinstance(size, int):
raise TypeError(f"argument should be integer or None, not '{type(size).__name__}'")
raise TypeError(
f"argument should be integer or None, not '{type(size).__name__}'"
)
if 0 <= size < len(self._buffer):
result = self._buffer[:size]
self._buffer = self._buffer[size:]
Expand All @@ -108,11 +124,13 @@ def read(self, size: int | None = -1) -> str:
self._buffer = got[size:]
return result + got[:size]

def readline(self, size: int =-1) -> str:
def readline(self, size: int = -1) -> str:
if not isinstance(size, int):
# For some reason sys.stdin.read(None) works, but
# sys.stdin.readline(None) raises a TypeError
raise TypeError(f"'{type(size).__name__}' object cannot be interpreted as an integer")
raise TypeError(
f"'{type(size).__name__}' object cannot be interpreted as an integer"
)
res = self.read(size)
[start, nl, rest] = res.partition("\n")
self._buffer = rest + self._buffer
Expand Down

0 comments on commit 45eec92

Please sign in to comment.