From dc19fedd18066c593189c4afd622a816ae5cc752 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Tue, 6 Oct 2026 11:52:42 -0700 Subject: [PATCH 1/4] pyproject.toml: Don't run ruff on processors dir --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 937f6b5..3fd0ac9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,9 @@ target-version = ['py312'] [tool.ruff] line-length = 120 +extend-exclude = ["pypcode/processors"] + +[tool.ruff.lint] extend-ignore = [ "E402", # Bottom imports ] From 7fa3c66cb5101978c40e9b2cdeebda7d068dfd17 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Tue, 6 Oct 2026 12:05:35 -0700 Subject: [PATCH 2/4] Mark setup.py, __main__.py executable --- pypcode/__main__.py | 0 setup.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 pypcode/__main__.py mode change 100644 => 100755 setup.py diff --git a/pypcode/__main__.py b/pypcode/__main__.py old mode 100644 new mode 100755 diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 From 0e30617219f2e666b63879194c68c99e10809e90 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Tue, 6 Oct 2026 11:55:37 -0700 Subject: [PATCH 3/4] Apply ruff lint auto-fixes --- pypcode/__init__.py | 35 +++++++++++++++++------------------ pypcode/__main__.py | 4 ++-- pypcode/printing.py | 2 +- pypcode/pypcode_native.pyi | 3 ++- scripts/benchmark.py | 5 ++--- setup.py | 2 +- tests/test_cli.py | 8 ++++---- tests/test_pypcode.py | 4 ++-- 8 files changed, 31 insertions(+), 32 deletions(-) diff --git a/pypcode/__init__.py b/pypcode/__init__.py index 45f0e1d..32e4470 100644 --- a/pypcode/__init__.py +++ b/pypcode/__init__.py @@ -3,19 +3,28 @@ """ from __future__ import annotations + import os.path import xml.etree.ElementTree as ET +from collections.abc import Generator, Mapping, Sequence from enum import IntEnum from typing import cast -from collections.abc import Generator, Sequence, Mapping from .__version__ import __version__ - from .pypcode_native import __version__ as __pypcode_native_version__ # pylint:disable=no-name-in-module assert __version__ == __pypcode_native_version__ +from .printing import ( + OpFormat, + OpFormatBinary, + OpFormatFunc, + OpFormatSpecial, + OpFormatUnary, + PcodePrettyPrinter, +) from .pypcode_native import ( # pylint:disable=no-name-in-module + TRANSLATE_FLAGS_BB_TERMINATING, Address, AddrSpace, BadDataError, @@ -25,25 +34,15 @@ LowlevelError, OpCode, PcodeOp, - TRANSLATE_FLAGS_BB_TERMINATING, Translation, UnimplError, Varnode, ) from .pypcode_native import Context as _Context # pylint:disable=no-name-in-module -from .printing import ( - OpFormat, - OpFormatBinary, - OpFormatFunc, - OpFormatSpecial, - OpFormatUnary, - PcodePrettyPrinter, -) - __all__ = [ - "Address", "AddrSpace", + "Address", "Arch", "ArchLanguage", "BadDataError", @@ -85,10 +84,10 @@ class ArchLanguage: """ __slots__ = ( + "_cspecs", + "_pspec", "archdir", "ldef", - "_pspec", - "_cspecs", ) archdir: str @@ -167,11 +166,11 @@ class Arch: """ __slots__ = ( - "archpath", "archname", - "ldefpath", - "ldef", + "archpath", "languages", + "ldef", + "ldefpath", ) archpath: str diff --git a/pypcode/__main__.py b/pypcode/__main__.py index e57761a..a41157e 100755 --- a/pypcode/__main__.py +++ b/pypcode/__main__.py @@ -66,7 +66,7 @@ def main(): print("\nSuggestions:") for langid in sorted(suggestions): print(" %-35s - %s" % (langid, langs[langid].description)) - print("") + print() print("Try `--list` for full list of architectures.") sys.exit(1) @@ -94,7 +94,7 @@ def main(): print(ctx.disassemble(disas_slice, disas_addr)) else: print(f" {i - last_imark_idx - 1:3d}: {op}") - print("") + print() except (BadDataError, UnimplError) as e: print(f"An error occurred during translation: {e}") sys.exit(1) diff --git a/pypcode/printing.py b/pypcode/printing.py index 8ff4f10..00ce952 100644 --- a/pypcode/printing.py +++ b/pypcode/printing.py @@ -18,7 +18,7 @@ class OpFormat: @staticmethod def fmt_vn(vn: Varnode) -> str: if vn.space.name == "const": - return "%#x" % vn.offset + return f"{vn.offset:#x}" elif vn.space.name == "register": name = vn.getRegisterName() if name: diff --git a/pypcode/pypcode_native.pyi b/pypcode/pypcode_native.pyi index b919827..c89186d 100644 --- a/pypcode/pypcode_native.pyi +++ b/pypcode/pypcode_native.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, ClassVar +from collections.abc import Callable +from typing import Any, ClassVar TRANSLATE_FLAGS_BB_TERMINATING: int __version__: str diff --git a/scripts/benchmark.py b/scripts/benchmark.py index 72898c0..cd6d70b 100755 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -15,10 +15,9 @@ import random import sys import time -from dataclasses import dataclass - -from typing import cast, Any from collections.abc import Callable, Iterable +from dataclasses import dataclass +from typing import Any, cast logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index a945e6d..9a4e54e 100755 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 import json import os -from pathlib import Path import platform import shutil import struct import subprocess import sys +from pathlib import Path from setuptools import setup from setuptools.command.build_ext import build_ext diff --git a/tests/test_cli.py b/tests/test_cli.py index af4719f..5da6aad 100755 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 # pylint:disable=no-self-use -import unittest import base64 -import tempfile -import sys -import os import io +import os +import sys +import tempfile +import unittest from unittest import mock from pypcode.__main__ import main diff --git a/tests/test_pypcode.py b/tests/test_pypcode.py index 4f258a8..a479ad5 100755 --- a/tests/test_pypcode.py +++ b/tests/test_pypcode.py @@ -3,9 +3,9 @@ import gc import logging -from unittest import main, TestCase -from unittest.mock import create_autospec from typing import cast +from unittest import TestCase, main +from unittest.mock import create_autospec from pypcode import ( AddrSpace, From d82bd69c5fc871907e631b24fa7ddb91ebbe0919 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Tue, 6 Oct 2026 14:21:11 -0700 Subject: [PATCH 4/4] Apply ruff lint manual fixes --- docs/conf.py | 2 +- pypcode/__main__.py | 4 ++-- pypcode/printing.py | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7a9ad5b..58f2ceb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,7 +9,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = "pypcode" -project_copyright = f"{datetime.datetime.now().year}, The angr Project contributors" +project_copyright = f"{datetime.datetime.now(tz=datetime.UTC).year}, The angr Project contributors" author = "The angr Project" # -- General configuration --------------------------------------------------- diff --git a/pypcode/__main__.py b/pypcode/__main__.py index a41157e..3172d46 100755 --- a/pypcode/__main__.py +++ b/pypcode/__main__.py @@ -52,7 +52,7 @@ def main(): langs = {lang.id: lang for arch in Arch.enumerate() for lang in arch.languages} if ("-l" in sys.argv) or ("--list" in sys.argv): for langid in sorted(langs): - print("%-35s - %s" % (langid, langs[langid].description)) + print(f"{langid:<35} - {langs[langid].description}") return args = ap.parse_args() @@ -65,7 +65,7 @@ def main(): if len(suggestions): print("\nSuggestions:") for langid in sorted(suggestions): - print(" %-35s - %s" % (langid, langs[langid].description)) + print(f" {langid:<35} - {langs[langid].description}") print() print("Try `--list` for full list of architectures.") sys.exit(1) diff --git a/pypcode/printing.py b/pypcode/printing.py index 00ce952..087fa3e 100644 --- a/pypcode/printing.py +++ b/pypcode/printing.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import ClassVar + from .pypcode_native import ( # pylint:disable=no-name-in-module Disassembly, Instruction, @@ -127,7 +129,7 @@ class PcodePrettyPrinter: DEFAULT_OP_FORMAT = OpFormat() - OP_FORMATS = { + OP_FORMATS: ClassVar[dict[OpCode, OpFormat]] = { OpCode.BOOL_AND: OpFormatBinary("&&"), OpCode.BOOL_NEGATE: OpFormatUnary("!"), OpCode.BOOL_OR: OpFormatBinary("||"),