Skip to content

Commit e34742d

Browse files
authored
Merge pull request #581 from enzbang/mypy-cleanup
Mypy cleanup
2 parents b370d35 + bdb92f8 commit e34742d

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ repos:
2424
- types-PyYAML
2525
- types-requests
2626
- types-setuptools
27+
- types-psutil

src/e3/anod/sandbox/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get_configuration(self) -> dict:
147147
return yaml.safe_load(f)
148148

149149
def write_scripts(self) -> None:
150-
from setuptools.command.easy_install import get_script_args # type: ignore[attr-defined]
150+
from setuptools.command.easy_install import ScriptWriter
151151

152152
# Retrieve sandbox_scripts entry points
153153
e3_distrib = get_distribution("e3-core")
@@ -161,7 +161,7 @@ def get_entry_map(self, group): # type: ignore
161161
def as_requirement(self): # type: ignore
162162
return e3_distrib.as_requirement()
163163

164-
for script in get_script_args(dist=SandboxDist()):
164+
for script in ScriptWriter.best().get_args(dist=SandboxDist()):
165165
script_name = script[0]
166166
script_content = script[1]
167167
target = os.path.join(self.bin_dir, script_name)
@@ -171,8 +171,8 @@ def as_requirement(self): # type: ignore
171171
"console_scripts", "sandbox_scripts"
172172
)
173173
with open(target, "wb") as f:
174-
if isinstance(script_content, str):
175-
f.write(script_content.encode("utf-8"))
174+
if isinstance(script_content, bytes): # type: ignore[unreachable]
175+
f.write(script_content) # type: ignore[unreachable]
176176
else:
177-
f.write(script_content)
177+
f.write(script_content.encode("utf-8"))
178178
chmod("a+x", target)

src/e3/net/http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import requests
1212
import requests.adapters
1313
import requests.exceptions
14-
import requests.packages.urllib3.exceptions
15-
from requests.packages.urllib3.util import Retry
14+
import urllib3.exceptions
15+
from urllib3.util import Retry
1616

1717
from typing import TYPE_CHECKING
1818

@@ -221,7 +221,7 @@ def request(
221221
except (
222222
socket.timeout,
223223
requests.exceptions.RequestException,
224-
requests.packages.urllib3.exceptions.HTTPError,
224+
urllib3.exceptions.HTTPError,
225225
) as e:
226226
# got an error with that base url so put it last in our list
227227
error_msgs.append(f"{message_prefix}{e}")

src/e3/os/process.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@
5656
try:
5757
import psutil
5858
from psutil import Popen
59+
60+
has_psutil = True
5961
except ImportError: # defensive code
60-
from subprocess import Popen
62+
from subprocess import Popen # type: ignore
6163

62-
psutil = None
64+
has_psutil = False
6365

6466

6567
def subprocess_setup() -> None:
@@ -419,7 +421,7 @@ def add_interpreter_command(cmd_line: CmdLine) -> CmdLine:
419421
self.internal = Popen(self.cmds[0], **popen_args)
420422

421423
else:
422-
runs: list[subprocess.Popen] = []
424+
runs: list[Popen] = []
423425
for index, cmd in enumerate(self.cmds):
424426
if index == 0:
425427
stdin: int | IO[Any] = self.input_file.fd
@@ -609,15 +611,15 @@ def interrupt(self) -> None:
609611

610612
def is_running(self) -> bool:
611613
"""Check whether the process is running."""
612-
if psutil is None: # defensive code
614+
if not has_psutil: # defensive code
613615
# psutil not imported, use our is_running function
614616
return is_running(self.pid)
615617
else:
616618
return self.internal.is_running()
617619

618620
def children(self) -> list[Any]:
619621
"""Return list of child processes (using psutil)."""
620-
if psutil is None: # defensive code
622+
if not has_psutil: # defensive code
621623
raise NotImplementedError("Run.children() require psutil")
622624
return self.internal.children()
623625

@@ -838,7 +840,7 @@ def kill_process_tree(pid: int | Any, timeout: int = 3) -> bool:
838840
except psutil.NoSuchProcess: # defensive code
839841
pass
840842

841-
def on_terminate(p: str) -> None:
843+
def on_terminate(p: psutil.Process) -> None:
842844
"""Log info when a process terminate."""
843845
logger.debug("process %s killed", p)
844846

0 commit comments

Comments
 (0)