Type hints, working test for byname ignore

This commit is contained in:
disinvite 2023-12-11 22:41:03 -05:00
parent 38b44e1246
commit 70f2a672ee
4 changed files with 17 additions and 13 deletions

View File

@ -1,5 +1,5 @@
from __future__ import annotations # python <3.10 compatibility
from enum import Enum from enum import Enum
from typing import Optional
from dataclasses import dataclass from dataclasses import dataclass
@ -62,7 +62,7 @@ class ParserError(Enum):
class ParserAlert: class ParserAlert:
code: ParserError code: ParserError
line_number: int line_number: int
line: str | None = None line: Optional[str] = None
def is_warning(self) -> bool: def is_warning(self) -> bool:
return self.code.value < ParserError.DECOMP_ERROR_START.value return self.code.value < ParserError.DECOMP_ERROR_START.value

View File

@ -1,3 +1,4 @@
from typing import List, Optional
from .parser import DecompParser from .parser import DecompParser
from .error import ParserAlert, ParserError from .error import ParserAlert, ParserError
@ -8,11 +9,11 @@ def get_checkorder_filter(module):
class DecompLinter: class DecompLinter:
def __init__(self): def __init__(self) -> None:
self.alerts = [] self.alerts: List[ParserAlert] = []
self._parser = DecompParser() self._parser = DecompParser()
self._filename = "" self._filename: str = ""
self._module = None self._module: Optional[str] = None
def reset(self): def reset(self):
self.alerts = [] self.alerts = []
@ -53,7 +54,7 @@ def _check_function_order(self):
last_offset = fun.offset last_offset = fun.offset
def _check_symbol_uniqueness(self): def _check_offset_uniqueness(self):
# TODO # TODO
pass pass
@ -85,7 +86,7 @@ def check_lines(self, lines, filename, module=None):
if self._module is not None: if self._module is not None:
self._check_byname_allowed() self._check_byname_allowed()
self._check_symbol_uniqueness() self._check_offset_uniqueness()
if not self.file_is_header(): if not self.file_is_header():
self._check_function_order() self._check_function_order()

View File

@ -56,7 +56,7 @@ def marker_is_vtable(marker: DecompMarker) -> bool:
class MarkerDict: class MarkerDict:
def __init__(self): def __init__(self) -> None:
self.markers: dict = {} self.markers: dict = {}
def insert(self, marker: DecompMarker) -> bool: def insert(self, marker: DecompMarker) -> bool:
@ -80,7 +80,7 @@ class DecompParser:
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
# Could combine output lists into a single list to get under the limit, # Could combine output lists into a single list to get under the limit,
# but not right now # but not right now
def __init__(self): def __init__(self) -> None:
# The lists to be populated as we parse # The lists to be populated as we parse
self.functions: List[ParserFunction] = [] self.functions: List[ParserFunction] = []
self.vtables: List[ParserVtable] = [] self.vtables: List[ParserVtable] = []

View File

@ -47,9 +47,12 @@ def test_byname_ignored(linter):
"// FUNCTION: TEST 0x2000", "// FUNCTION: TEST 0x2000",
"void function2() {}", "void function2() {}",
] ]
# TODO: This will fail after enforcing that bynames belong in headers # This will fail because byname lookup does not belong in the cpp file
assert linter.check_lines(lines, "test.cpp", "TEST") is True assert linter.check_lines(lines, "test.cpp", "TEST") is False
assert len(linter.alerts) == 0 # but it should not fail for function order.
assert all(
alert.code != ParserError.FUNCTION_OUT_OF_ORDER for alert in linter.alerts
)
def test_module_isolation(linter): def test_module_isolation(linter):