Skip to content

Commit

Permalink
pre-commit: Update all hook versions and apply fixes
Browse files Browse the repository at this point in the history
Vermin 1.6.0 was recently released, which contains a fix for
netromdk/vermin#230. This was a rather odd corner case, in which Vermin
would fail when code was compatible with 2.x and 3.x, yet the command
line only required compatibility with 3.x. Since pre-commit runs against
only files that changed, this was possible, for example with small test
files. I'm not sure if I encountered it in drgn (I know I did with
drgn-tools), but it's good to have the fix.

I used pre-commit autoupdate, so we have the latest version of each hook
now. In particular, this commit surpasses mypy 0.971, which is the last
version to support Python 3.6 at runtime. Mypy still supports targeting
Python 3.6[1].

[1]: https://mypy-lang.blogspot.com/2022/07/mypy-0971-released.html

Two new errors were surfaced with the new hooks:

1. Mypy complained about the pattern "os.exit(exception)". I've replaced
   these so they explicitly use str: "os.exit(str(exception))".

drgn/cli.py:283: error: Argument 1 to "exit" has incompatible type "OSError"; expected "str | int | None"  [arg-type]

2. Vermin complained that "int.is_integer()" was introduced 3.12. I
   surmised that it was unable to infer that its usage was guaranteed to
   be against a float, and the reason was due to the division operation
   against an integer. I changed the integer literal to a float literal,
   which resolved the issue.

!2, 3.12     drgn/helpers/common/format.py
  'int.is_integer' member requires !2, 3.12

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
  • Loading branch information
brenns10 committed Nov 27, 2023
1 parent f391a94 commit e83ab80
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ repos:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
rev: v1.7.1
hooks:
- id: mypy
args: [--show-error-codes, --strict, --no-warn-return-any, --no-warn-unused-ignores]
Expand All @@ -31,7 +31,7 @@ repos:
- id: debug-statements
- id: check-merge-conflict
- repo: https://github.com/netromdk/vermin
rev: v1.5.2
rev: v1.6.0
hooks:
- id: vermin
# The vmtest package in general should adhere to the same version
Expand Down
4 changes: 2 additions & 2 deletions drgn/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _main() -> None:
try:
script_type = _identify_script(args.script[0])
except OSError as e:
sys.exit(e)
sys.exit(str(e))
if script_type == "core":
sys.exit(
f"error: {args.script[0]} is a core dump\n"
Expand Down Expand Up @@ -280,7 +280,7 @@ def _main() -> None:
else:
prog.set_core_dump(open_via_sudo("/proc/kcore", os.O_RDONLY))
except OSError as e:
sys.exit(e)
sys.exit(str(e))
except ValueError as e:
# E.g., "not an ELF core file"
sys.exit(f"error: {e}")
Expand Down
2 changes: 1 addition & 1 deletion drgn/helpers/common/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def number_in_binary_units(n: SupportsFloat, precision: int = 1) -> str:
for prefix in ("", "K", "M", "G", "T", "P", "E", "Z"):
if abs(n) < 1024:
break
n /= 1024
n /= 1024.0
else:
prefix = "Y"
if n.is_integer():
Expand Down

0 comments on commit e83ab80

Please sign in to comment.