Skip to content

Commit

Permalink
Fix type checking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed Dec 22, 2023
1 parent 15cbacf commit 5c44773
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 59 deletions.
12 changes: 8 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"linenums",
"Linu",
"lsprotocol",
"lspt",
"mkdocs",
"mkdocstrings",
"Moiré",
Expand All @@ -57,7 +58,7 @@
"ungroup",
"Xino"
],
"python.testing.pytestArgs": ["--log-level=DEBUG", "-s"],
"python.testing.pytestArgs": ["."],
"ruff.enable": true,
"ruff.fixAll": true,
"python.analysis.importFormat": "absolute",
Expand All @@ -76,7 +77,7 @@
},
"python.analysis.fixAll": ["source.convertImportFormat"],
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"editor.formatOnSaveMode": "file",
"editor.formatOnSave": true,
Expand Down Expand Up @@ -107,7 +108,7 @@
"depth": 10
}
],
"mypy-type-checker.importStrategy": "useBundled",
"mypy-type-checker.importStrategy": "fromEnvironment",
"black-formatter.importStrategy": "useBundled",
"cSpell.ignoreWords": ["RRGGBB", "RRGGBBAA"],
"workbench.colorCustomizations": {
Expand All @@ -130,5 +131,8 @@
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#007fff",
"mypy-type-checker.args": ["--config-file=pyproject.toml"]
"mypy-type-checker.args": ["--config-file=pyproject.toml"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"mypy-type-checker.reportingScope": "workspace"
}
4 changes: 3 additions & 1 deletion src/pygerber/backend/rasterized_2d/backend_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def __init__(self, options: Rasterized2DBackendOptions | None = None) -> None:
if options is not None and not isinstance(options, Rasterized2DBackendOptions):
msg = ( # type: ignore[unreachable]
"Expected Rasterized2DBackendOptions or None as options, got "
+ str(type(options))
+ str(
type(options),
)
)
raise TypeError(msg)
super().__init__(options)
Expand Down
4 changes: 1 addition & 3 deletions src/pygerber/gerberx3/api/_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ class Rasterized2DLayer(Layer):
def __init__(self, options: Rasterized2DLayerParams) -> None:
"""Initialize Layer object."""
if not isinstance(options, Rasterized2DLayerParams):
msg = ( # type: ignore[unreachable]
f"Expected {Rasterized2DLayerParams} got {type(options)}."
)
msg = f"Expected {Rasterized2DLayerParams} got {type(options)}." # type: ignore[unreachable]

Check warning on line 309 in src/pygerber/gerberx3/api/_layers.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/api/_layers.py#L309

Added line #L309 was not covered by tests
raise TypeError(msg)
super().__init__(options)

Expand Down
6 changes: 3 additions & 3 deletions src/pygerber/gerberx3/language_server/_internals/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, ls: LanguageServer, source: str, uri: str) -> None:
lspt.MessageType.Info,
)

self.parser_error_diagnostics = []
self.parser_error_diagnostics: list[diagnostic.Diagnostic] = []
self.options = ParserOptions(

Check warning on line 41 in src/pygerber/gerberx3/language_server/_internals/document.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/language_server/_internals/document.py#L40-L41

Added lines #L40 - L41 were not covered by tests
on_update_drawing_state_error=self.on_update_drawing_state_error,
)
Expand Down Expand Up @@ -82,8 +82,8 @@ def on_update_drawing_state_error(
diagnostic.Diagnostic(
range=(
diagnostic.Range(
token.get_token_position(),
token.get_token_end_position(),
start=token.get_token_position(),
end=token.get_token_end_position(),
)
),
message=message,
Expand Down
2 changes: 1 addition & 1 deletion src/pygerber/gerberx3/language_server/_internals/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _text_document_completion(
lspt.CompletionItem(
label=f"G{code}*",
kind=lspt.CompletionItemKind.Keyword,
) # type: ignore[pylance]
)
for code in [
"01",
"02",
Expand Down
2 changes: 1 addition & 1 deletion src/pygerber/gerberx3/math/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _operator(
min_x=op(self.min_x, -other),
min_y=op(self.min_y, -other),
)
return NotImplemented # type: ignore[unreachable]
return NotImplemented

Check warning on line 126 in src/pygerber/gerberx3/math/bounding_box.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/math/bounding_box.py#L126

Added line #L126 was not covered by tests

def __add__(self, other: object) -> BoundingBox:
if isinstance(other, BoundingBox):
Expand Down
6 changes: 3 additions & 3 deletions src/pygerber/gerberx3/math/offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _compare(
return op(self.value, other.value) # type: ignore[no-any-return]
if isinstance(other, (Decimal, int, float, str)):
return op(self.value, Decimal(other)) # type: ignore[no-any-return]
return NotImplemented # type: ignore[unreachable]
return NotImplemented

Check warning on line 81 in src/pygerber/gerberx3/math/offset.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/math/offset.py#L81

Added line #L81 was not covered by tests

def __eq__(self, other: object) -> bool:
return self._compare(other, operator.eq)
Expand All @@ -104,7 +104,7 @@ def _operator(
return Offset(value=op(self.value, other.value))
if isinstance(other, (Decimal, int, float, str)):
return Offset(value=op(self.value, Decimal(other)))
return NotImplemented # type: ignore[unreachable]
return NotImplemented

Check warning on line 107 in src/pygerber/gerberx3/math/offset.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/math/offset.py#L107

Added line #L107 was not covered by tests

def __add__(self, other: object) -> Offset:
return self._operator(other, operator.add)
Expand Down Expand Up @@ -138,7 +138,7 @@ def _i_operator(
"value": op(self.value, Decimal(other)),
},
)
return NotImplemented # type: ignore[unreachable]
return NotImplemented

Check warning on line 141 in src/pygerber/gerberx3/math/offset.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/math/offset.py#L141

Added line #L141 was not covered by tests

def __iadd__(self, other: object) -> Self:
return self._i_operator(other, operator.add)
Expand Down
4 changes: 2 additions & 2 deletions src/pygerber/gerberx3/math/vector_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _operator(
x=op(self.x, Decimal(other)),
y=op(self.y, Decimal(other)),
)
return NotImplemented # type: ignore[unreachable]
return NotImplemented

Check warning on line 57 in src/pygerber/gerberx3/math/vector_2d.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/math/vector_2d.py#L57

Added line #L57 was not covered by tests

def __add__(self, other: object) -> Vector2D:
return self._operator(other, operator.add)
Expand Down Expand Up @@ -97,7 +97,7 @@ def _i_operator(
"y": op(self.y, Decimal(other)),
},
)
return NotImplemented # type: ignore[unreachable]
return NotImplemented

Check warning on line 100 in src/pygerber/gerberx3/math/vector_2d.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/math/vector_2d.py#L100

Added line #L100 was not covered by tests

def __iadd__(self, other: object) -> Self:
return self._i_operator(other, operator.add)
Expand Down
2 changes: 1 addition & 1 deletion src/pygerber/gerberx3/tokenizer/tokens/bases/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_gerber_code_one_line_pretty_display(self) -> str:
def get_token_diagnostics(self) -> Iterable[diagnostic.Diagnostic]:
"""Get diagnostics for this token."""
return
yield
yield # type: ignore[unreachable]

Check warning on line 126 in src/pygerber/gerberx3/tokenizer/tokens/bases/token.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/tokenizer/tokens/bases/token.py#L125-L126

Added lines #L125 - L126 were not covered by tests

def get_token_end_position(self) -> Position:
"""Get position of the end of the token."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
zeros_mode = TrailingZerosMode(tokens["zeros_mode"])
coordinate_mode = CoordinateMode(tokens["coordinate_mode"])
x_format = AxisFormat(
integer=int(tokens["x_format"][0]), # type: ignore[pylance]
decimal=int(tokens["x_format"][1]), # type: ignore[pylance]
integer=int(tokens["x_format"][0]),
decimal=int(tokens["x_format"][1]),
)
y_format = AxisFormat(
integer=int(tokens["y_format"][0]), # type: ignore[pylance]
decimal=int(tokens["y_format"][1]), # type: ignore[pylance]
integer=int(tokens["y_format"][0]),
decimal=int(tokens["y_format"][1]),
)
return cls(
string=string,
Expand Down
4 changes: 2 additions & 2 deletions src/pygerber/gerberx3/tokenizer/tokens/invalid_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def get_token_diagnostics(self) -> Iterable[diagnostic.Diagnostic]:
yield diagnostic.Diagnostic(

Check warning on line 35 in src/pygerber/gerberx3/tokenizer/tokens/invalid_token.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/gerberx3/tokenizer/tokens/invalid_token.py#L35

Added line #L35 was not covered by tests
range=(
diagnostic.Range(
self.get_token_position(),
self.get_token_end_position(),
start=self.get_token_position(),
end=self.get_token_end_position(),
)
),
message="Invalid syntax.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
string=string,
location=location,
name=name,
value=value, # type: ignore[pylance]
value=value,
)

def get_gerber_code(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
string=string,
location=location,
name=name,
value=value, # type: ignore[pylance]
value=value,
)

def get_gerber_code(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
string=string,
location=location,
name=name,
value=value, # type: ignore[pylance]
value=value,
)

def get_gerber_code(
Expand Down
6 changes: 3 additions & 3 deletions src/pygerber/sequence_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def flatten(sequence: Iterable[T]) -> Iterable[T]:
def unwrap(item: T) -> T:
"""Unwrap item wrapped in sequences."""
try:
while isinstance(item, (list, tuple, ParseResults)): # type: ignore[index]
item = item[0] # type: ignore[unreachable, return-value]
while isinstance(item, (list, tuple, ParseResults)):
item = item[0]

Check warning on line 38 in src/pygerber/sequence_tools.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/sequence_tools.py#L37-L38

Added lines #L37 - L38 were not covered by tests
except (TypeError, IndexError):
pass

return item # type: ignore[unreachable, return-value]
return item

Check warning on line 42 in src/pygerber/sequence_tools.py

View check run for this annotation

Codecov / codecov/patch

src/pygerber/sequence_tools.py#L42

Added line #L42 was not covered by tests
4 changes: 2 additions & 2 deletions test/gerberx3/test_grammar/test_build_d_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

@pytest.fixture()
def d_codes() -> ParserElement:
return GerberGrammarBuilder()._build_d_codes() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_d_codes()


@pytest.fixture()
def d_codes_raw() -> ParserElement:
return GerberGrammarBuilder( # type: ignore[no-any-return]
return GerberGrammarBuilder(
is_raw=True,
)._build_d_codes()

Expand Down
4 changes: 2 additions & 2 deletions test/gerberx3/test_grammar/test_build_define_aperture.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

@pytest.fixture()
def define_aperture() -> ParserElement:
return GerberGrammarBuilder()._build_define_aperture() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_define_aperture()


@pytest.fixture()
def define_aperture_raw() -> ParserElement:
return GerberGrammarBuilder(is_raw=True)._build_define_aperture() # type: ignore[no-any-return]
return GerberGrammarBuilder(is_raw=True)._build_define_aperture()


TEST_DATA = [
Expand Down
4 changes: 2 additions & 2 deletions test/gerberx3/test_grammar/test_build_format_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

@pytest.fixture()
def format_specifier() -> ParserElement:
return GerberGrammarBuilder()._build_format_specifier() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_format_specifier()


@pytest.fixture()
def format_specifier_raw() -> ParserElement:
return GerberGrammarBuilder(is_raw=True)._build_format_specifier() # type: ignore[no-any-return]
return GerberGrammarBuilder(is_raw=True)._build_format_specifier()


FORMAT_SPECIFIER_DATA = [
Expand Down
8 changes: 4 additions & 4 deletions test/gerberx3/test_grammar/test_build_g_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@

@pytest.fixture()
def g_codes() -> ParserElement:
return GerberGrammarBuilder()._build_g_codes() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_g_codes()


@pytest.fixture()
def eoex() -> ParserElement:
return GerberGrammarBuilder()._build_eoex() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_eoex()


@pytest.fixture()
def g_codes_raw() -> ParserElement:
return GerberGrammarBuilder( # type: ignore[no-any-return]
return GerberGrammarBuilder(
is_raw=True,
)._build_g_codes()


@pytest.fixture()
def eoex_raw() -> ParserElement:
return GerberGrammarBuilder( # type: ignore[no-any-return]
return GerberGrammarBuilder(
is_raw=True,
)._build_eoex()

Expand Down
20 changes: 10 additions & 10 deletions test/gerberx3/test_grammar/test_build_load_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class TestLoadName:
@staticmethod
@pytest.fixture()
def load_name() -> ParserElement:
return GerberGrammarBuilder()._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_load_commands()

@staticmethod
@pytest.fixture()
def load_name_raw() -> ParserElement:
return GerberGrammarBuilder(is_raw=True)._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder(is_raw=True)._build_load_commands()

LOAD_NAME_DATA: ClassVar[list[str]] = [
"%LN2G09E752G0.gbl*%",
Expand Down Expand Up @@ -61,12 +61,12 @@ class TestLoadScaling:
@staticmethod
@pytest.fixture()
def load_scale() -> ParserElement:
return GerberGrammarBuilder()._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_load_commands()

@staticmethod
@pytest.fixture()
def load_scale_raw() -> ParserElement:
return GerberGrammarBuilder(is_raw=True)._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder(is_raw=True)._build_load_commands()

LOAD_SCALE_DATA: ClassVar[list[str]] = [
"%LS0.8*%",
Expand Down Expand Up @@ -108,12 +108,12 @@ class TestLoadRotation:
@staticmethod
@pytest.fixture()
def load_rotation() -> ParserElement:
return GerberGrammarBuilder()._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_load_commands()

@staticmethod
@pytest.fixture()
def load_rotation_raw() -> ParserElement:
return GerberGrammarBuilder(is_raw=True)._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder(is_raw=True)._build_load_commands()

LOAD_ROTATION_DATA: ClassVar[list[str]] = [
"%LR0.0*%",
Expand Down Expand Up @@ -155,12 +155,12 @@ class TestLoadMirroring:
@staticmethod
@pytest.fixture()
def load_mirroring() -> ParserElement:
return GerberGrammarBuilder()._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_load_commands()

@staticmethod
@pytest.fixture()
def load_mirroring_raw() -> ParserElement:
return GerberGrammarBuilder(is_raw=True)._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder(is_raw=True)._build_load_commands()

LOAD_MIRRORING_DATA: ClassVar[list[str]] = [
"%LMN*%",
Expand Down Expand Up @@ -209,12 +209,12 @@ class TestLoadPolarity:
@staticmethod
@pytest.fixture()
def load_polarity() -> ParserElement:
return GerberGrammarBuilder()._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder()._build_load_commands()

@staticmethod
@pytest.fixture()
def load_polarity_raw() -> ParserElement:
return GerberGrammarBuilder(is_raw=True)._build_load_commands() # type: ignore[no-any-return]
return GerberGrammarBuilder(is_raw=True)._build_load_commands()

LOAD_POLARITY_DATA: ClassVar[list[str]] = [
"%LPC*%",
Expand Down
Loading

0 comments on commit 5c44773

Please sign in to comment.