App, lib, cmds: Remove unreachable code
Remove dead code paths detected by the new warn_unreachable mypy rule. These include: - Removed always-false isinstance checks (ssh/util.py, templates.py) - Removed unreachable return statements after raise (FileContext.py) - Removed unreachable None checks for typed variables (Result.py, ExecContext.py, CmdGetAuthInfo.py) - Simplified __uri function by removing impossible None check (CopyContext.py) - Changed assert False to explicit error (Cmd.py) - Removed unreachable None case from match (App.py) - Removed redundant outer case _: pass (pkg_relations.py) - Restructured stdin write to avoid unreachable warning (AsyncSSH.py) Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL and pi.dev 0.81.1 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
a1d192b048
commit
c16e054aaa
11 changed files with 7 additions and 25 deletions
|
|
@ -85,7 +85,7 @@ class App(Base):
|
||||||
return path
|
return path
|
||||||
case 'relative':
|
case 'relative':
|
||||||
return os.path.relpath(path)
|
return os.path.relpath(path)
|
||||||
case None | 'absolute':
|
case 'absolute':
|
||||||
return os.path.abspath(path)
|
return os.path.abspath(path)
|
||||||
case _:
|
case _:
|
||||||
m = re.search(r'^make:(\S+)$', fmt)
|
m = re.search(r'^make:(\S+)$', fmt)
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,6 @@ class CmdGetAuthInfo(Cmd): # export
|
||||||
for key, val in result.items():
|
for key, val in result.items():
|
||||||
if not getattr(args, key, None):
|
if not getattr(args, key, None):
|
||||||
continue
|
continue
|
||||||
if val is None:
|
|
||||||
continue
|
|
||||||
if args.only_values:
|
if args.only_values:
|
||||||
print(val)
|
print(val)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -161,8 +161,6 @@ def pkg_relations(
|
||||||
expanded_dep[1] = '>>'
|
expanded_dep[1] = '>>'
|
||||||
case _:
|
case _:
|
||||||
pass
|
pass
|
||||||
case _:
|
|
||||||
pass
|
|
||||||
dep_str = ' '.join(expanded_dep)
|
dep_str = ' '.join(expanded_dep)
|
||||||
if quote:
|
if quote:
|
||||||
dep_str = '"' + dep_str + '"'
|
dep_str = '"' + dep_str + '"'
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,7 @@ def merge_values(*values: RenderValues) -> ListDict:
|
||||||
rhs_dict = render_values_to_list_dict(rhs)
|
rhs_dict = render_values_to_list_dict(rhs)
|
||||||
for key, val in rhs_dict.items():
|
for key, val in rhs_dict.items():
|
||||||
entry = ret.setdefault(key, [])
|
entry = ret.setdefault(key, [])
|
||||||
if isinstance(val, list):
|
entry += val
|
||||||
entry += val
|
|
||||||
else:
|
|
||||||
entry.append(val)
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def format_list_dict(
|
def format_list_dict(
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,7 @@ class AbstractCmd(abc.ABC):
|
||||||
self, cmds: Cmd | list[Cmd] | Types[Any] | list[Types[Any]]
|
self, cmds: Cmd | list[Cmd] | Types[Any] | list[Types[Any]]
|
||||||
) -> None:
|
) -> None:
|
||||||
if isinstance(cmds, Cmd):
|
if isinstance(cmds, Cmd):
|
||||||
assert False
|
raise NotImplementedError('Single Cmd should be handled elsewhere')
|
||||||
return
|
|
||||||
if isinstance(cmds, list):
|
if isinstance(cmds, list):
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
self.add_subcommands(cmd)
|
self.add_subcommands(cmd)
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,7 @@ class CopyContext:
|
||||||
chroot = False
|
chroot = False
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
def __uri(ctx: FileContext | Uri | str) -> Uri | str | None:
|
def __uri(ctx: FileContext | Uri | str) -> Uri | str:
|
||||||
if ctx is None:
|
|
||||||
return None
|
|
||||||
if isinstance(ctx, Uri):
|
if isinstance(ctx, Uri):
|
||||||
return ctx
|
return ctx
|
||||||
if isinstance(ctx, str):
|
if isinstance(ctx, str):
|
||||||
|
|
|
||||||
|
|
@ -150,9 +150,7 @@ class ExecContext(Base):
|
||||||
interactive = sys.stdin.isatty()
|
interactive = sys.stdin.isatty()
|
||||||
else:
|
else:
|
||||||
interactive = False
|
interactive = False
|
||||||
if cmd_input is None:
|
if isinstance(cmd_input, str):
|
||||||
cmd_input_bytes = None
|
|
||||||
elif isinstance(cmd_input, str):
|
|
||||||
cmd_input_bytes = cmd_input.encode(sys.stdout.encoding or 'utf-8')
|
cmd_input_bytes = cmd_input.encode(sys.stdout.encoding or 'utf-8')
|
||||||
else:
|
else:
|
||||||
cmd_input_bytes = cmd_input
|
cmd_input_bytes = cmd_input
|
||||||
|
|
|
||||||
|
|
@ -297,7 +297,6 @@ class FileContext(abc.ABC):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log(ERR, f'{self.log_name}: Failed to stat({path}) ({str(e)})')
|
log(ERR, f'{self.log_name}: Failed to stat({path}) ({str(e)})')
|
||||||
raise
|
raise
|
||||||
return False
|
|
||||||
|
|
||||||
async def is_dir(self, path: str, follow_symlinks = True) -> bool:
|
async def is_dir(self, path: str, follow_symlinks = True) -> bool:
|
||||||
return await self._is_dir(self._chroot(path), follow_symlinks = follow_symlinks)
|
return await self._is_dir(self._chroot(path), follow_symlinks = follow_symlinks)
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,6 @@ class Result:
|
||||||
if self.status == 0:
|
if self.status == 0:
|
||||||
return False
|
return False
|
||||||
err = self.stderr_str
|
err = self.stderr_str
|
||||||
if err is None:
|
|
||||||
return False
|
|
||||||
import re
|
import re
|
||||||
return re.search(pattern, err) is not None
|
return re.search(pattern, err) is not None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,9 +210,8 @@ class AsyncSSH(Base):
|
||||||
except (BrokenPipeError, OSError):
|
except (BrokenPipeError, OSError):
|
||||||
pass
|
pass
|
||||||
return
|
return
|
||||||
if proc.stdin is None:
|
if proc.stdin is not None:
|
||||||
return
|
proc.stdin.write(data)
|
||||||
proc.stdin.write(data)
|
|
||||||
await proc.stdin.drain()
|
await proc.stdin.drain()
|
||||||
|
|
||||||
async def _pump_stdout() -> None:
|
async def _pump_stdout() -> None:
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,6 @@ def join_cmd(
|
||||||
"""
|
"""
|
||||||
ret: list[str] = []
|
ret: list[str] = []
|
||||||
for token in cmd:
|
for token in cmd:
|
||||||
if not isinstance(token, str):
|
|
||||||
token = str(token)
|
|
||||||
if token in operators:
|
if token in operators:
|
||||||
ret.append(token)
|
ret.append(token)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue