mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-18 03:19:53 +00:00
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:
@@ -184,7 +184,7 @@ class PatcherDoc(TypedDict):
|
||||
class InputDoc(TypedDict):
|
||||
name: str
|
||||
description: str
|
||||
type: Union[str, list[str]]
|
||||
type: NotRequired[Union[str, list[str]]]
|
||||
default: NotRequired[Any]
|
||||
generic_type: NotRequired[str]
|
||||
enum_items: NotRequired[list[str]]
|
||||
@@ -201,7 +201,7 @@ def _extract_docs(cls: type, method_name: str, boilerplate_args: Union[Sequence[
|
||||
for name, parameter in signature.parameters.items():
|
||||
if name == "self" or name in boilerplate_args:
|
||||
continue
|
||||
input_doc: InputDoc = {"name": name}
|
||||
input_doc: InputDoc = {"name": name, "description": "Undocumented"}
|
||||
inputs[name] = input_doc
|
||||
if isinstance(parameter.default, (str, float, int, bool)):
|
||||
input_doc["default"] = parameter.default
|
||||
@@ -267,10 +267,6 @@ def _extract_docs(cls: type, method_name: str, boilerplate_args: Union[Sequence[
|
||||
assert is_valid_filter_glob(filter_glob), f"Invalid filter_glob pattern: '{filter_glob}'."
|
||||
inputs[param_name]["filter_glob"] = filter_glob
|
||||
|
||||
for param_name in inputs:
|
||||
if "description" not in inputs[param_name]:
|
||||
inputs[param_name]["description"] = "Undocumented"
|
||||
|
||||
docs = PatcherDoc(
|
||||
class_=cls,
|
||||
description=doc_description,
|
||||
@@ -309,6 +305,7 @@ def parse_docstring(docstring: str) -> DocstringData:
|
||||
line = line[1:]
|
||||
if line.startswith(PREFIXES):
|
||||
prefix = line.split(" ")[0]
|
||||
assert prefix in PREFIXES, f"Invalid line: '{line}'."
|
||||
current_section = prefix
|
||||
match_ = re.match(rf"{prefix}\s+(\w+):\s+(.*)", line)
|
||||
assert match_, f"Invalid line: '{line}'."
|
||||
|
||||
@@ -71,6 +71,7 @@ class Patcher:
|
||||
|
||||
# Sort elements by GlobalId to ensure consistent order
|
||||
elements_sorted = sorted(elements, key=lambda x: x.GlobalId)
|
||||
element_quantities = None
|
||||
for element in elements_sorted:
|
||||
quantities = self.get_element_quantities(element)
|
||||
if quantities:
|
||||
|
||||
@@ -521,7 +521,7 @@ class Patcher(ifcpatch.BasePatcher):
|
||||
data_type = "JSON"
|
||||
json_attrs.append(i)
|
||||
else:
|
||||
print("Possibly not implemented attribute data type:", attribute, primitive)
|
||||
assert False, f"{attribute}, {primitive}"
|
||||
if not self.is_strict or derived[i]:
|
||||
optional = "DEFAULT NULL"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user