Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Dec 17, 2024
1 parent a57c15d commit 90317aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
11 changes: 6 additions & 5 deletions IPython/utils/_process_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import subprocess
import os
import shlex
import subprocess
import sys
import os
from typing import Callable, Optional, Union, List
from typing import IO, Any, Callable, List, Union

from IPython.utils import py3compat

#-----------------------------------------------------------------------------
# Function definitions
#-----------------------------------------------------------------------------

def read_no_interrupt(p: subprocess.Popen) -> str:
def read_no_interrupt(stream: IO[Any]) -> bytes:
"""Read from a pipe ignoring EINTR errors.
This is necessary because when reading from pipes with GUI event loops
Expand All @@ -34,7 +35,7 @@ def read_no_interrupt(p: subprocess.Popen) -> str:
import errno

try:
return p.read()
return stream.read()
except IOError as err:
if err.errno != errno.EINTR:
raise
Expand Down
37 changes: 21 additions & 16 deletions IPython/utils/_process_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
#-----------------------------------------------------------------------------

# stdlib
import ctypes
import os
import subprocess
import sys
import ctypes
import time

from ctypes import c_int, POINTER
from ctypes.wintypes import LPCWSTR, HLOCAL
from subprocess import STDOUT, TimeoutExpired
from ctypes import POINTER, c_int
from ctypes.wintypes import HLOCAL, LPCWSTR
from subprocess import STDOUT
from threading import Thread
import subprocess
from types import TracebackType
from typing import IO, Any, List, Optional

from typing import Optional, List
import traceback
from . import py3compat
from ._process_common import arg_split as py_arg_split

# our own imports
from ._process_common import read_no_interrupt, process_handler, arg_split as py_arg_split
from . import py3compat
from ._process_common import process_handler, read_no_interrupt
from .encoding import DEFAULT_ENCODING

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -72,7 +72,7 @@ def __enter__(self) -> Optional[str]:
return None

def __exit__(
self, exc_type: Optional[type], exc_value: Optional[BaseException], traceback
self, exc_type: Optional[type[BaseException]], exc_value: Optional[BaseException], traceback:TracebackType
) -> None:
if self.is_unc_path:
os.chdir(self.path)
Expand All @@ -82,18 +82,23 @@ def _system_body(p: subprocess.Popen) -> int:
"""Callback for _system."""
enc = DEFAULT_ENCODING

# Dec 2024: in both of these functions, I'm not sure why we .splitlines()
# the bytes and then decode each line individually instead of just decoding
# the whole thing at once.
def stdout_read() -> None:
try:
for line in read_no_interrupt(p.stdout).splitlines():
line = line.decode(enc, "replace")
assert p.stdout is not None
for byte_line in read_no_interrupt(p.stdout).splitlines():
line = byte_line.decode(enc, "replace")
print(line, file=sys.stdout)
except Exception as e:
print(f"Error reading stdout: {e}", file=sys.stderr)

def stderr_read() -> None:
try:
for line in read_no_interrupt(p.stderr).splitlines():
line = line.decode(enc, "replace")
assert p.stderr is not None
for byte_line in read_no_interrupt(p.stderr).splitlines():
line = byte_line.decode(enc, "replace")
print(line, file=sys.stderr)
except Exception as e:
print(f"Error reading stderr: {e}", file=sys.stderr)
Expand Down Expand Up @@ -204,7 +209,7 @@ def arg_split(
)
if arg is not None
]
retval = LocalFree(result_pointer)
LocalFree(result_pointer)
return result
except AttributeError:
arg_split = py_arg_split
Expand Down

0 comments on commit 90317aa

Please sign in to comment.