Skip to content

Commit 16c21cb

Browse files
authored
Merge pull request #7 from Decompollaborate/develop
2.0.1
2 parents ff70076 + 7ed9ae0 commit 16c21cb

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[project]
55
name = "mapfile_parser"
6-
version = "2.0.0"
6+
version = "2.0.1"
77
description = "Map file parser library focusing decompilation projects"
88
readme = "README.md"
99
requires-python = ">=3.7"

src/mapfile_parser/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
__version_info__ = (2, 0, 0)
8+
__version_info__ = (2, 0, 1)
99
__version__ = ".".join(map(str, __version_info__))
1010
__author__ = "Decompollaborate"
1111

src/mapfile_parser/mapfile.py

+37-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import dataclasses
99
import re
10-
from typing import Generator
10+
from typing import Any, Generator
1111
from pathlib import Path
1212

1313
from .progress_stats import ProgressStats
@@ -75,8 +75,8 @@ def printAsCsv(self):
7575
print(f"{self.name},{self.vram:08X},{self.size}")
7676

7777

78-
def toJson(self) -> dict:
79-
result = {
78+
def toJson(self) -> dict[str, Any]:
79+
result: dict[str, Any] = {
8080
"name": self.name,
8181
"vram": self.getVramStr(),
8282
"size": self.serializeSize(),
@@ -86,6 +86,16 @@ def toJson(self) -> dict:
8686
return result
8787

8888

89+
def __eq__(self, other: object) -> bool:
90+
if not isinstance(other, Symbol):
91+
return False
92+
return self.name == other.name and self.vram == other.vram
93+
94+
# https://stackoverflow.com/a/56915493/6292472
95+
def __hash__(self):
96+
return hash((self.name, self.vram))
97+
98+
8999
@dataclasses.dataclass
90100
class File:
91101
filepath: Path
@@ -182,8 +192,8 @@ def printAsCsv(self, printVram: bool=True):
182192
print(f"{self.filepath},{self.sectionType},{symCount},{maxSize},{self.size},{averageSize:0.2f}")
183193

184194

185-
def toJson(self) -> dict:
186-
fileDict: dict = {
195+
def toJson(self) -> dict[str, Any]:
196+
fileDict: dict[str, Any] = {
187197
"filepath": str(self.filepath),
188198
"sectionType": self.sectionType,
189199
"vram": self.serializeVram(),
@@ -212,6 +222,15 @@ def __setitem__(self, index, sym: Symbol):
212222
def __len__(self) -> int:
213223
return len(self._symbols)
214224

225+
def __eq__(self, other: object) -> bool:
226+
if not isinstance(other, File):
227+
return False
228+
return self.filepath == other.filepath
229+
230+
# https://stackoverflow.com/a/56915493/6292472
231+
def __hash__(self):
232+
return hash((self.filepath,))
233+
215234

216235
@dataclasses.dataclass
217236
class Segment:
@@ -314,8 +333,8 @@ def printSymbolsCsv(self):
314333
return
315334

316335

317-
def toJson(self) -> dict:
318-
segmentDict: dict = {
336+
def toJson(self) -> dict[str, Any]:
337+
segmentDict: dict[str, Any] = {
319338
"name": self.name,
320339
"vram": self.serializeVram(),
321340
"size": self.serializeSize(),
@@ -341,6 +360,15 @@ def __getitem__(self, index) -> File:
341360
def __len__(self) -> int:
342361
return len(self._filesList)
343362

363+
def __eq__(self, other: object) -> bool:
364+
if not isinstance(other, Segment):
365+
return False
366+
return self.name == other.name and self.vram == other.vram and self.size == other.size and self.vrom == other.vrom
367+
368+
# https://stackoverflow.com/a/56915493/6292472
369+
def __hash__(self):
370+
return hash((self.name, self.vram, self.size, self.vrom))
371+
344372

345373
class MapFile:
346374
def __init__(self):
@@ -623,12 +651,12 @@ def printSymbolsCsv(self):
623651
return
624652

625653

626-
def toJson(self) -> dict:
654+
def toJson(self) -> dict[str, Any]:
627655
segmentsList = []
628656
for segment in self._segmentsList:
629657
segmentsList.append(segment.toJson())
630658

631-
result = {
659+
result: dict[str, Any] = {
632660
"segments": segmentsList
633661
}
634662
return result

0 commit comments

Comments
 (0)