Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 14, 2024
1 parent 4acdee9 commit 8eb8d6b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 60 deletions.
2 changes: 1 addition & 1 deletion pypcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __init__(self, name: str, ldefpath: str):
self.ldefpath = ldefpath

# Parse ldefs file into structured format
with open(ldefpath, "r") as f:
with open(ldefpath) as f:
self.ldef = LanguageDefinitions.from_xml(f.read())

# Create ArchLanguage objects from structured data
Expand Down
45 changes: 21 additions & 24 deletions pypcode/cspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

@dataclass
class DataOrganization:
absolute_max_alignment: Optional[int] = None
machine_alignment: Optional[int] = None
default_alignment: Optional[int] = None
default_pointer_alignment: Optional[int] = None
wchar_size: Optional[int] = None
short_size: Optional[int] = None
integer_size: Optional[int] = None
long_size: Optional[int] = None
long_long_size: Optional[int] = None
float_size: Optional[int] = None
double_size: Optional[int] = None
long_double_size: Optional[int] = None
size_alignment_map: Dict[int, int] = field(default_factory=dict)
absolute_max_alignment: int | None = None
machine_alignment: int | None = None
default_alignment: int | None = None
default_pointer_alignment: int | None = None
wchar_size: int | None = None
short_size: int | None = None
integer_size: int | None = None
long_size: int | None = None
long_long_size: int | None = None
float_size: int | None = None
double_size: int | None = None
long_double_size: int | None = None
size_alignment_map: dict[int, int] = field(default_factory=dict)
bitfield_packing_uses_ms: bool = False

@classmethod
def from_element(cls, element: ET.Element) -> DataOrganization:
if element is None:
return cls()

def get_int_attr(elem: ET.Element, attr: str) -> Optional[int]:
def get_int_attr(elem: ET.Element, attr: str) -> int | None:
# Handle both attribute and element value cases
if attr in elem.attrib:
return int(elem.attrib[attr])
Expand All @@ -49,10 +49,7 @@ def get_int_attr(elem: ET.Element, attr: str) -> Optional[int]:
uses_ms = False
if packing_elem is not None:
ms_conv = packing_elem.find("use_MS_convention")
uses_ms = (
ms_conv is not None
and ms_conv.attrib.get("value", "false").lower() == "true"
)
uses_ms = ms_conv is not None and ms_conv.attrib.get("value", "false").lower() == "true"

return cls(
absolute_max_alignment=get_int_attr(element, "absolute_max_alignment"),
Expand All @@ -75,7 +72,7 @@ def get_int_attr(elem: ET.Element, attr: str) -> Optional[int]:
@dataclass
class GlobalScope:
ram_present: bool = False
registers: List[str] = field(default_factory=list)
registers: list[str] = field(default_factory=list)

@classmethod
def from_element(cls, element: ET.Element) -> GlobalScope:
Expand All @@ -92,11 +89,11 @@ def from_element(cls, element: ET.Element) -> GlobalScope:
class CompilerSpec:
data_organization: DataOrganization = field(default_factory=DataOrganization)
global_scope: GlobalScope = field(default_factory=GlobalScope)
stackpointer_register: Optional[str] = None
returnaddress_register: Optional[str] = None
returnaddress_space: Optional[str] = None
returnaddress_offset: Optional[int] = None
returnaddress_size: Optional[int] = None
stackpointer_register: str | None = None
returnaddress_register: str | None = None
returnaddress_space: str | None = None
returnaddress_offset: int | None = None
returnaddress_size: int | None = None

@classmethod
def from_xml(cls, xml_string: str) -> CompilerSpec:
Expand Down
12 changes: 6 additions & 6 deletions pypcode/ldefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class Language:
slafile: str
processorspec: str
id: str
description: Optional[str] = None
manualindexfile: Optional[str] = None
instructionEndian: Optional[str] = None
compilers: List[Compiler] = field(default_factory=list)
external_names: List[ExternalName] = field(default_factory=list)
description: str | None = None
manualindexfile: str | None = None
instructionEndian: str | None = None
compilers: list[Compiler] = field(default_factory=list)
external_names: list[ExternalName] = field(default_factory=list)

@classmethod
def from_element(cls, element: ET.Element) -> Language:
Expand All @@ -66,7 +66,7 @@ def from_element(cls, element: ET.Element) -> Language:

@dataclass
class LanguageDefinitions:
languages: List[Language] = field(default_factory=list)
languages: list[Language] = field(default_factory=list)

@classmethod
def from_xml(cls, xml_string: str) -> LanguageDefinitions:
Expand Down
34 changes: 17 additions & 17 deletions pypcode/pspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def from_element(cls, element: ET.Element) -> Property:

@dataclass
class Properties:
properties: Dict[str, str] = field(default_factory=dict)
properties: dict[str, str] = field(default_factory=dict)

@classmethod
def from_element(cls, element: ET.Element) -> Properties:
Expand All @@ -32,8 +32,8 @@ def from_element(cls, element: ET.Element) -> Properties:
@dataclass
class ContextSet:
space: str
values: Dict[str, int]
description: Dict[str, str]
values: dict[str, int]
description: dict[str, str]

@classmethod
def from_element(cls, element: ET.Element) -> ContextSet:
Expand All @@ -50,7 +50,7 @@ def from_element(cls, element: ET.Element) -> ContextSet:
@dataclass
class TrackedSet:
space: str
values: Dict[str, int]
values: dict[str, int]

@classmethod
def from_element(cls, element: ET.Element) -> TrackedSet:
Expand All @@ -66,8 +66,8 @@ def from_element(cls, element: ET.Element) -> TrackedSet:

@dataclass
class ContextData:
context_set: Optional[ContextSet] = None
tracked_set: Optional[TrackedSet] = None
context_set: ContextSet | None = None
tracked_set: TrackedSet | None = None

@classmethod
def from_element(cls, element: ET.Element) -> ContextData:
Expand All @@ -83,8 +83,8 @@ def from_element(cls, element: ET.Element) -> ContextData:
@dataclass
class Register:
name: str
group: Optional[str] = None
vector_lane_sizes: Optional[Set[int]] = None
group: str | None = None
vector_lane_sizes: set[int] | None = None
hidden: bool = False

@classmethod
Expand All @@ -103,7 +103,7 @@ def from_element(cls, element: ET.Element) -> Register:

@dataclass
class RegisterData:
registers: List[Register] = field(default_factory=list)
registers: list[Register] = field(default_factory=list)

@classmethod
def from_element(cls, element: ET.Element) -> RegisterData:
Expand All @@ -119,7 +119,7 @@ class DefaultSymbol:
name: str
address: str
entry: bool
type: Optional[str] = None
type: str | None = None

@classmethod
def from_element(cls, element: ET.Element) -> DefaultSymbol:
Expand All @@ -133,7 +133,7 @@ def from_element(cls, element: ET.Element) -> DefaultSymbol:

@dataclass
class DefaultSymbols:
symbols: List[DefaultSymbol] = field(default_factory=list)
symbols: list[DefaultSymbol] = field(default_factory=list)

@classmethod
def from_element(cls, element: ET.Element) -> DefaultSymbols:
Expand All @@ -146,12 +146,12 @@ def from_element(cls, element: ET.Element) -> DefaultSymbols:

@dataclass
class ProcessorSpec:
properties: Optional[Properties]
programcounter: Optional[str]
context_data: Optional[ContextData]
register_data: Optional[RegisterData]
default_symbols: Optional[DefaultSymbols]
incidentalcopy: Optional[List[str]] = None
properties: Properties | None
programcounter: str | None
context_data: ContextData | None
register_data: RegisterData | None
default_symbols: DefaultSymbols | None
incidentalcopy: list[str] | None = None

@classmethod
def from_xml(cls, xml_string: str) -> ProcessorSpec:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_all_cspecs(self):
"""Test that we can parse all compiler specs without errors."""
for cspec_path in self.all_cspecs:
with self.subTest(cspec_path=cspec_path):
with open(cspec_path, "r") as f:
with open(cspec_path) as f:
cspec = CompilerSpec.from_xml(f.read())

# Basic validation of parsed data
Expand All @@ -28,7 +28,7 @@ def test_all_cspecs(self):
def test_x86_64_win_cspec(self):
"""Test specific x86-64 Windows compiler spec."""
cspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86-64-win.cspec"
with open(cspec_path, "r") as f:
with open(cspec_path) as f:
cspec = CompilerSpec.from_xml(f.read())

# Test data organization
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_x86_64_win_cspec(self):
def test_x86_64_gcc_cspec(self):
"""Test specific x86-64 GCC compiler spec."""
cspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86-64-gcc.cspec"
with open(cspec_path, "r") as f:
with open(cspec_path) as f:
cspec = CompilerSpec.from_xml(f.read())

# Test data organization
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_x86_64_gcc_cspec(self):
def test_aarch64_cspec(self):
"""Test specific AArch64 compiler spec."""
cspec_path = PROCESSORS_DIR / "AARCH64" / "data" / "languages" / "AARCH64.cspec"
with open(cspec_path, "r") as f:
with open(cspec_path) as f:
cspec = CompilerSpec.from_xml(f.read())

# Test data organization
Expand All @@ -113,7 +113,7 @@ def test_aarch64_cspec(self):
def test_x86_32_gcc_cspec(self):
"""Test specific x86 32-bit GCC compiler spec."""
cspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86gcc.cspec"
with open(cspec_path, "r") as f:
with open(cspec_path) as f:
cspec = CompilerSpec.from_xml(f.read())

# Test data organization
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_x86_32_gcc_cspec(self):
def test_arm_32_cspec(self):
"""Test specific ARM 32-bit compiler spec."""
cspec_path = PROCESSORS_DIR / "ARM" / "data" / "languages" / "ARM.cspec"
with open(cspec_path, "r") as f:
with open(cspec_path) as f:
cspec = CompilerSpec.from_xml(f.read())

# Test data organization
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ldefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_all_ldefs(self):
"""Test that we can parse all language definition files without errors."""
for ldefs_path in self.all_ldefs:
with self.subTest(ldefs_path=ldefs_path):
with open(ldefs_path, "r") as f:
with open(ldefs_path) as f:
ldefs = LanguageDefinitions.from_xml(f.read())

# Basic validation of parsed data
Expand All @@ -36,7 +36,7 @@ def test_all_ldefs(self):
def test_x86_ldefs(self):
"""Test specific x86 language definitions."""
ldefs_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86.ldefs"
with open(ldefs_path, "r") as f:
with open(ldefs_path) as f:
ldefs = LanguageDefinitions.from_xml(f.read())

# Test basic properties
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_x86_ldefs(self):
def test_arm_ldefs(self):
"""Test specific ARM language definitions."""
ldefs_path = PROCESSORS_DIR / "ARM" / "data" / "languages" / "ARM.ldefs"
with open(ldefs_path, "r") as f:
with open(ldefs_path) as f:
ldefs = LanguageDefinitions.from_xml(f.read())

# Test that we have both BE and LE variants
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_all_pspecs(self):
"""Test that we can parse all processor specs without errors."""
for pspec_path in self.all_pspecs:
with self.subTest(pspec_path=pspec_path):
with open(pspec_path, "r") as f:
with open(pspec_path) as f:
pspec = ProcessorSpec.from_xml(f.read())

# Basic validation of parsed data
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_all_pspecs(self):
def test_x86_pspec(self):
"""Test specific x86 processor spec."""
pspec_path = PROCESSORS_DIR / "x86" / "data" / "languages" / "x86.pspec"
with open(pspec_path, "r") as f:
with open(pspec_path) as f:
pspec = ProcessorSpec.from_xml(f.read())

# Test specific x86 properties
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_x86_pspec(self):
def test_arm_cortex_pspec(self):
"""Test specific ARM Cortex processor spec."""
pspec_path = PROCESSORS_DIR / "ARM" / "data" / "languages" / "ARMCortex.pspec"
with open(pspec_path, "r") as f:
with open(pspec_path) as f:
pspec = ProcessorSpec.from_xml(f.read())

# Test ARM Cortex specific properties
Expand Down

0 comments on commit 8eb8d6b

Please sign in to comment.