Update littlecheck

Commit c12b8ed (Clean up some lints, 2025-08-28)
This commit is contained in:
Johannes Altmanninger
2025-10-11 16:44:14 +02:00
parent 9ae9db7f70
commit 5102c8b137

View File

@@ -17,7 +17,7 @@ import unicodedata
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
from itertools import izip_longest as zip_longest # type: ignore
# Directives can occur at the beginning of a line, or anywhere in a line that does not start with #.
@@ -41,7 +41,7 @@ SKIP = object()
def find_command(program):
import os
path, name = os.path.split(program)
path, _ = os.path.split(program)
if path:
return os.path.isfile(program) and os.access(program, os.X_OK)
for path in os.environ["PATH"].split(os.pathsep):
@@ -302,6 +302,8 @@ class TestFailure(object):
if a
else ""
)
# Convince type checker that bstr will in fact be a string when read.
bstr = ""
if b:
bstr = (
"on line "
@@ -388,13 +390,8 @@ def runproc(cmd, env=None):
async def runproc_async(cmd, env=None):
"""Wrapper around subprocess.Popen to save typing"""
PIPE = asyncio.subprocess.PIPE
DEVNULL = asyncio.subprocess.DEVNULL
return await asyncio.create_subprocess_shell(
cmd,
stdin=DEVNULL,
stdout=PIPE,
stderr=PIPE,
env=env,
cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env
)
@@ -498,11 +495,17 @@ class TestRun(object):
print(self.subbed_command)
proc = await runproc_async(self.subbed_command, env=self.env)
stdout, stderr = await proc.communicate()
# Work around type system limitations / bad API design which makes the typechecker unhappy.
if proc.returncode is None:
raise RuntimeError(
"After `proc.communicate()` the return code must be an int."
)
status = proc.returncode
# HACK: This is quite cheesy: POSIX specifies that sh should return 127 for a missing command.
# It's also possible that it'll be returned in other situations,
# most likely when the last command in a shell script doesn't exist.
# So we check if the command *we execute* exists, and complain then.
status = proc.returncode
cmd = next(
(
word
@@ -594,8 +597,7 @@ class CheckCmd(object):
raise NotImplementedError
@staticmethod
def parse(line, checktype):
# type: (Line) -> CheckCmd
def parse(line: Line, checktype: str) -> "CheckCmd":
# Everything inside {{}} is a regular expression.
# Everything outside of it is a literal string.
# Split around {{...}}. Then every odd index will be a regex, and
@@ -693,6 +695,11 @@ async def check_file_async(input_file, name, subs, config, failure_handler, env=
for reqcmd in checker.requirecmds:
proc = await runproc_async(perform_substitution(reqcmd.args, subs), env=env)
await proc.communicate()
# Work around type system limitations / bad API design which makes the typechecker unhappy.
if proc.returncode is None:
raise RuntimeError(
"After `proc.communicate()` the return code must be an int."
)
if proc.returncode > 0:
return SKIP