Fix all ty diagnostics on ifcviewer-wgpu (ci-lint ty-ios + ty-bonsai)

This branch carried v0.8.0's strict `[tool.ty.rules] all = "error"` config but
not the source fixes that were made upstream to satisfy it, so both ci-lint ty
gates were failing: `poe ty-ios` reported 256 diagnostics and `poe ty-bonsai`
258. Both are now clean.

Most fixes are ported from v0.8.0 and follow two idioms: initialise a name
before a conditional that may not bind it (plus an `assert` where the invariant
is real but not provable), and close an exhaustive `if`/`elif` chain with
`else: assert False, <discriminant>`.

The branch's own newer accessors are preserved throughout - `.file`,
`.declaration`, `file.types()`, `get_max_id()` are kept rather than reverted to
`wrapped_data.*`, and non-ty upstream changes (notably the in-progress geometry
cache removal) are deliberately not pulled in.

Notable fixes that are not straight ports:

* ifcopenshell_wrapper.pyi: `entity_instance.file` was declared as
  `def file(self) -> file`, where the property name shadows the `class file`
  below it, so the annotation resolved to `Unknown`. Every `element.file` in
  the codebase was therefore unchecked. Qualifying it to `ifcopenshell.file`
  restores `.schema` to its Literal union and surfaces no new diagnostics.

* model/wall.py: a duplicated merge fragment in the void-straddle path ran an
  always-true `if void_straddles:` that read `new_opening` from the mutually
  exclusive branch (stale value, or NameError on the first iteration), followed
  by an unreachable duplicate `elif`. Removing it makes the file match v0.8.0.

* light/operator.py: upstream's own fix unpacks three targets from two values
  and raises ValueError unconditionally; corrected to `None, None, None`.

* assign_system.py, validate.py, geom/main.py: walrus-in-genexp is valid at
  runtime (PEP 572 binds in the containing scope) but ty does not model it;
  rewritten as explicit loops, matching upstream.

Verified: poe ty-ios, poe ty-bonsai, ruff check src/ nix/, black --check .,
and compileall -W error at py3.10 (ifcopenshell-python) and py3.11 (bonsai).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-07-27 19:14:39 +10:00
parent a522f31ba4
commit 19a1d88970
106 changed files with 430 additions and 89 deletions
+10 -4
View File
@@ -25,9 +25,10 @@ import re
from collections import defaultdict
from collections.abc import Callable
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, Union
from typing import TYPE_CHECKING, Any, Literal, Union, cast
import ifcopenshell.util.selector
from typing_extensions import assert_never
try:
from openpyxl import Workbook
@@ -100,8 +101,9 @@ class Parser:
def parse(self, ifc_file: ifcopenshell.file, name=None):
for category_name, category_config in self.config["categories"].items():
for element in category_config["get_category_elements"](ifc_file):
get_element_data: Union[GetElementDataCallBack, dict[str, Any]]
get_element_data = category_config["get_element_data"]
get_element_data = cast(
Union[GetElementDataCallBack, dict[str, Any]], category_config["get_element_data"]
)
if isinstance(get_element_data, dict):
data = {}
@@ -109,14 +111,18 @@ class Parser:
data[key] = ifcopenshell.util.selector.get_element_value(element, query)
elif isinstance(get_element_data, Callable):
data = get_element_data(ifc_file, element) or {}
else:
assert_never(get_element_data)
get_custom_element_data = self.get_custom_element_data.get(category_name, lambda x, y: None)
get_custom_element_data = self.get_custom_element_data.get(category_name, lambda *_: None)
if isinstance(get_custom_element_data, dict):
custom_data = {}
for key, query in get_custom_element_data.items():
custom_data[key] = ifcopenshell.util.selector.get_element_value(element, query)
elif isinstance(get_custom_element_data, Callable):
custom_data = get_custom_element_data(ifc_file, element) or {}
else:
assert_never(get_custom_element_data)
data.update(custom_data)
+2
View File
@@ -271,6 +271,8 @@ def get_contact_data(ifc_file: ifcopenshell.file, element: ifcopenshell.entity_i
pao = the_actor
person = the_actor.ThePerson
organization = the_actor.TheOrganization
else:
assert False, the_actor
email = get_email_from_pao(person, organization)
+1
View File
@@ -20,6 +20,7 @@ dependencies = [
"openpyxl",
"odfpy",
"pandas",
"typing-extensions",
]
[project.urls]