Skip to content

Commit

Permalink
Fix missing mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Feb 24, 2023
1 parent 675863a commit a093c5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ show_error_codes = True
warn_unused_ignores = True
strict = True

[mypy-reportlab.pdfgen.canvas]
[mypy-reportlab.*]
ignore_missing_imports = True
26 changes: 18 additions & 8 deletions LabelGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import math
import sys

from typing import Tuple, Union, Optional, List
from typing import Tuple, Union, Optional, List, TypeAlias

ResistorList: TypeAlias = List[Union[Optional[float], List[Optional[float]]]]


def load_font(font_name: str) -> None:
Expand Down Expand Up @@ -521,14 +523,22 @@ def draw_resistor_sticker(
rect.height/13, get_eia98_code(resistor_value))


def render_stickers(c: Canvas, layout: PaperConfig, values: List[object], draw_center_line: bool = True) -> None:
def render_stickers(c: Canvas, layout: PaperConfig, values: ResistorList, draw_center_line: bool = True) -> None:
def flatten(elem: Union[Optional[float], List[Optional[float]]]) -> List[Optional[float]]:
if isinstance(elem, list):
return elem
else:
return [elem]

# Flatten
values_flat: List[Union[float, None]] = [item for sublist in values for item in sublist]
values_flat: List[Optional[float]] = [elem for nested in values for elem in flatten(nested)]

# Draw stickers
for (position, value) in enumerate(values_flat):
rowId = position // 3
columnId = position % 3

for (rowId, row) in enumerate(values):
for (columnId, value) in enumerate(row):
if value is None:
continue
if value is not None:
draw_resistor_sticker(c, layout, rowId, columnId, value, draw_center_line, False)
if mirror:
draw_resistor_sticker(c, layout, rowId, columnId, value, False, True)
Expand Down Expand Up @@ -562,7 +572,7 @@ def main() -> None:
#
# Add "None" if no label should get generated at a specific position.
# ############################################################################
resistor_values = [
resistor_values: ResistorList = [
[0, 0.02, .1],
[1, 12, 13],
[210, 220, 330],
Expand Down

0 comments on commit a093c5e

Please sign in to comment.