diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py index bc9f4d5453..5dc3bf3aeb 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/unassign_representation.py @@ -96,8 +96,8 @@ class Usecase: ifcopenshell.util.element.remove_deep2(self.file, representation_map) def unassign_products_using_mapped_representation(self, representation_map: ifcopenshell.entity_instance) -> None: - mapped_representations = [] - just_representations = [] + mapped_representations: list[dict[str, ifcopenshell.entity_instance]] = [] + just_representations: list[ifcopenshell.entity_instance] = [] for map_usage in representation_map.MapUsage or []: for inverse in self.file.get_inverse(map_usage): if not inverse.is_a("IfcShapeRepresentation"): @@ -109,4 +109,4 @@ class Usecase: for item in mapped_representations: self.unassign_product_representation(item["product"], item["representation"]) for representation in just_representations: - ifcopenshell.api.geometry.remove_representation(self.file, **{"representation": representation}) + ifcopenshell.api.geometry.remove_representation(self.file, representation=representation) diff --git a/src/ifcopenshell-python/ifcopenshell/entity_instance.py b/src/ifcopenshell-python/ifcopenshell/entity_instance.py index d125e77373..5e0426364b 100644 --- a/src/ifcopenshell-python/ifcopenshell/entity_instance.py +++ b/src/ifcopenshell-python/ifcopenshell/entity_instance.py @@ -17,6 +17,7 @@ # along with IfcOpenShell. If not, see . +from __future__ import annotations import functools import importlib import numbers @@ -25,12 +26,15 @@ import operator import subprocess import sys import time -from typing import Union, Any, TypeVar, overload +from typing import Union, Any, TypeVar, overload, TYPE_CHECKING from collections.abc import Callable, Sequence from . import ifcopenshell_wrapper from . import settings +if TYPE_CHECKING: + import ifcopenshell + try: import logging except ImportError: @@ -150,7 +154,8 @@ class entity_instance: wrapped_data: ifcopenshell_wrapper.entity_instance - def __init__(self, e, file=None): + def __init__(self, e: ifcopenshell_wrapper.entity_instance, file: Union[ifcopenshell.file] = None): + # TODO: when it is a tuple? if isinstance(e, tuple): e = ifcopenshell_wrapper.new_IfcBaseClass(*e) super().__setattr__("wrapped_data", e) @@ -423,7 +428,7 @@ class entity_instance: """Return the STEP numerical identifier""" return self.wrapped_data.id() - def __eq__(self, other: "entity_instance") -> bool: + def __eq__(self, other: entity_instance) -> bool: if not isinstance(self, type(other)): return False elif None in (self.wrapped_data.file, other.wrapped_data.file): diff --git a/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi b/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi index a4a88e8f01..9cb135c48f 100644 --- a/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi +++ b/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcOpenShell. If not, see . -from typing import Any +from typing import Any, Union # `std::vector` usually translated to `tuple[xxx, ...]`. @@ -832,12 +832,12 @@ class file: guid_map_: Any stream: Any def FreshId(self): ... - def add(self, entity, id): ... + def add(self, entity: entity_instance, id: int) -> entity_instance: ... def addEntities(self, entities): ... def batch(self): ... def build_inverses(self): ... - def by_guid(self, guid): ... - def by_id(self, id): ... + def by_guid(self, guid: str) -> entity_instance: ... + def by_id(self, id: int) -> entity_instance: ... def by_type(self, *args): ... def by_type_excl_subtypes(self, *args): ... @staticmethod @@ -848,9 +848,15 @@ class file: def getMaxId(self): ... def getTotalInverses(self, instance_id): ... def getUnit(self, unit_type): ... - def get_inverse(self, e): ... - def get_inverse_indices(self, *args): ... - def get_total_inverses(self, e): ... + def get_inverse(self, e: entity_instance) -> tuple[entity_instance, ...]: ... + def get_inverse_indices(self, *args: Union[entity_instance, int]) -> tuple[int, ...]: + """Get the attribute indices for each inverse from `get_inverse`, that reference the provided entity.. + + :param args: entity or it's id. Maximum 1 entity at the time. + """ + ... + + def get_total_inverses(self, e: entity_instance) -> int: ... def good(self): ... @staticmethod def guid_map(*args): ... @@ -862,14 +868,14 @@ class file: def internal_guid_map(self): ... def load(self, entity_instance_name, entity, arg4, attribute_index): ... def recalculate_id_counter(self): ... - def remove(self, entity): ... + def remove(self, entity: entity_instance) -> None: ... @property def schema(self): ... def to_string(self): ... @staticmethod - def traverse(instance, max_level): ... + def traverse(instance: entity_instance, max_level: int) -> tuple[entity_instance, ...]: ... @staticmethod - def traverse_breadth_first(instance, max_level): ... + def traverse_breadth_first(instance: entity_instance, max_level: int) -> tuple[entity_instance, ...]: ... def try_read_semicolon(self): ... def types(self) -> tuple[str, ...]: """Return a tuple of classes present in the file. diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 042d46c751..0c8bf9c47a 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -1592,7 +1592,7 @@ def remove_deep2( if not are_inverses_contained(): return - to_delete = set() + to_delete: set[ifcopenshell.entity_instance] = set() subgraph = list(ifc_file.traverse(element, breadth_first=True)) subgraph.extend(also_consider) subgraph_set = set(subgraph)