python: add type annotations

This commit is contained in:
2025-04-08 04:48:36 +00:00
parent 0975bd149e
commit eb975c1972
4 changed files with 43 additions and 26 deletions

10
main.py
View File

@@ -38,7 +38,7 @@ DEFAULT_BATTERY = "ldtek"
logger = logging.getLogger(__name__)
def export_png_image(obj, file_: str, orientation: str):
def export_png_image(obj: cq.Workplane, file_: str, orientation: str) -> None:
assy = _to_assy(obj)
renderer = toVTK(assy)
win = vtkRenderWindow()
@@ -77,7 +77,7 @@ def export_png_image(obj, file_: str, orientation: str):
exporter.Write()
def _model(as_assy: bool=False):
def _model(as_assy: bool=False) -> cq.Workplane:
logger.info("computing model ...")
battery_name = os.environ.get("CASE_BATTERY", DEFAULT_BATTERY)
render_phone = os.environ.get("CASE_RENDER_PHONE", "") not in ("", "0")
@@ -93,8 +93,8 @@ def _model(as_assy: bool=False):
battery = ldtek_battery.LdtekBattery()
return case.case(phone, battery=battery, render_phone=render_phone, as_assy=as_assy)
_computedModels = {}
def model(as_assy: bool=False):
_computedModels: dict[(bool,), cq.Workplane] = {}
def model(as_assy: bool=False) -> cq.Workplane:
""" memoized wrapper around `_model` """
global _computedModels
key = (as_assy, )
@@ -102,7 +102,7 @@ def model(as_assy: bool=False):
_computedModels[key] = _model(as_assy=as_assy)
return _computedModels[key]
def main():
def main() -> None:
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)