From 92a222cda7a4e008ba309b5130011e5eef8c2671 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 30 May 2025 12:08:02 +0500 Subject: [PATCH] typing --- src/bcf/bcf/v3/bcfapi.py | 2 +- src/bsdd/bsdd.py | 2 +- src/ifc2ca/ifc2ca.py | 2 ++ src/ifccsv/ifccsv.py | 1 + src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py | 25 ++++++++++++++---------- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/bcf/bcf/v3/bcfapi.py b/src/bcf/bcf/v3/bcfapi.py index 90b47de258..788e0e459c 100644 --- a/src/bcf/bcf/v3/bcfapi.py +++ b/src/bcf/bcf/v3/bcfapi.py @@ -21,7 +21,7 @@ import http.server import os import tempfile import time -import urllib +import urllib.parse import uuid import webbrowser from re import A diff --git a/src/bsdd/bsdd.py b/src/bsdd/bsdd.py index 266b2a4cc3..9292008439 100644 --- a/src/bsdd/bsdd.py +++ b/src/bsdd/bsdd.py @@ -19,7 +19,7 @@ from __future__ import annotations import uuid import time -import urllib +import urllib.parse import requests import webbrowser import http.server diff --git a/src/ifc2ca/ifc2ca.py b/src/ifc2ca/ifc2ca.py index 5ee3d29154..41411cfae3 100644 --- a/src/ifc2ca/ifc2ca.py +++ b/src/ifc2ca/ifc2ca.py @@ -40,6 +40,8 @@ from .scriptCodeAster import CommandFileConstructor class Ifc2CA: + file: ifcopenshell.file + folder_path = None salome_path = None model_keys = ["id", "type", "GlobalId", "Name", "LoadedBy", "HasResults"] diff --git a/src/ifccsv/ifccsv.py b/src/ifccsv/ifccsv.py index df4b54a0c0..743cae0936 100755 --- a/src/ifccsv/ifccsv.py +++ b/src/ifccsv/ifccsv.py @@ -559,6 +559,7 @@ if __name__ == "__main__": ) elif getattr(args, "import"): ifc_csv = IfcCsv() + ifc_file: ifcopenshell.file ifc_file = ifcopenshell.open(args.ifc) ifc_csv.Import( ifc_file, diff --git a/src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py b/src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py index d4ef3feba9..a3268d0460 100644 --- a/src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py +++ b/src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py @@ -24,6 +24,7 @@ import time import tempfile import typing import itertools +import logging import numpy as np import multiprocessing import ifcopenshell @@ -62,8 +63,8 @@ DEFAULT_DATABASE_NAME = "database" class Patcher: def __init__( self, - file, - logger, + file: ifcopenshell.file, + logger: logging.Logger, sql_type: SQLTypes = "SQLite", host: str = "localhost", username: str = "root", @@ -140,7 +141,7 @@ class Patcher: # Assume it's a filepath - existing or not. pass - self.schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(self.file.schema_identifier) + self.schema = ifcopenshell.schema_by_name(self.file.schema_identifier) if self.sql_type == "sqlite": self.db = sqlite3.connect(database) @@ -278,6 +279,8 @@ class Patcher: PRIMARY KEY (`ifc_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; """ + else: + assert False self.c.execute(statement) def create_metadata(self) -> None: @@ -353,6 +356,7 @@ class Patcher: else: statement += "ifc_id INTEGER PRIMARY KEY NOT NULL UNIQUE" + assert isinstance(declaration, ifcopenshell.ifcopenshell_wrapper.entity) total_attributes = declaration.attribute_count() if total_attributes: @@ -393,6 +397,7 @@ class Patcher: statement = f"CREATE TABLE IF NOT EXISTS {ifc_class} (" statement += "`ifc_id` int(10) unsigned NOT NULL," + assert isinstance(declaration, ifcopenshell.ifcopenshell_wrapper.entity) derived = declaration.derived() for attribute in declaration.all_attributes(): primitive = ifcopenshell.util.attribute.get_primitive_type(attribute) @@ -434,13 +439,13 @@ class Patcher: def insert_data(self, ifc_class: str) -> None: elements = self.file.by_type(ifc_class, include_subtypes=False) - rows = [] - id_map_rows = [] - pset_rows = [] + rows: list[Any] = [] + id_map_rows: list[tuple[int, str]] = [] + pset_rows: list[tuple[int, str, str, Any]] = [] for element in elements: - nested_indices = [] - values = [element.id()] + nested_indices: list[int] = [] + values: list[Any] = [element.id()] for i, attribute in enumerate(element): if isinstance(attribute, ifcopenshell.entity_instance): if attribute.id(): @@ -473,7 +478,7 @@ class Patcher: else: rows.append(values) - id_map_rows.append([element.id(), ifc_class]) + id_map_rows.append((element.id(), ifc_class)) if self.should_get_psets: psets = ifcopenshell.util.element.get_psets(element) @@ -483,7 +488,7 @@ class Patcher: continue if isinstance(value, list): value = json.dumps(value) - pset_rows.append([element.id(), pset_name, prop_name, value]) + pset_rows.append((element.id(), pset_name, prop_name, value)) if self.should_get_geometry: if element.id() not in self.shape_rows and (placement := getattr(element, "ObjectPlacement", None)):