From 59b17fc593274340b070cef8d95f43fbd91fb028 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 30 May 2025 17:17:53 +0500 Subject: [PATCH] ifcopenshell_wrapper.pyi --- .../ifcopenshell/ifcopenshell_wrapper.pyi | 36 +++++++++++++------ .../ifcopenshell/util/schema.py | 2 +- .../util/scripts/validate_stub.py | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi b/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi index 1f03e93043..068b17d3e7 100644 --- a/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi +++ b/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi @@ -18,6 +18,8 @@ from typing import Any +# `std::vector` usually translated to `tuple[xxx, ...]`. + ON_SLABS_AND_WALLS: Any ON_SLABS_AT_FLOORPLANS: Any ALWAYS: Any @@ -564,9 +566,9 @@ class aggregation_type(parameter_type): def type_of_element(self): ... class attribute: - def name(self): ... - def optional(self): ... - def type_of_attribute(self): ... + def name(self) -> str: ... + def optional(self) -> bool: ... + def type_of_attribute(self) -> parameter_type: ... class attribute_value_derived: ... @@ -699,12 +701,13 @@ class cylinder(surface): def matrix(self): ... class declaration: + def _is(self, *args: str) -> bool: ... def as_entity(self): ... def as_enumeration_type(self): ... def as_select_type(self): ... def as_type_declaration(self): ... def index_in_schema(self): ... - def name(self): ... + def name(self) -> str: ... def name_uc(self): ... def schema(self): ... def type(self): ... @@ -739,11 +742,14 @@ class entity(declaration): def all_inverse_attributes(self): ... def argument_types(self): ... def as_entity(self): ... - def attribute_by_index(self, index): ... - def attribute_count(self): ... + def attribute_by_index(self, index: int) -> attribute: ... + def attribute_count(self) -> int: ... def attribute_index(self, *args): ... def attributes(self): ... - def derived(self): ... + def derived(self) -> tuple[bool, ...]: + """Return a tuple of booleans indicating whether each direct attribute is derived.""" + ... + def is_abstract(self): ... def set_attributes(self, attributes, derived): ... def set_inverse_attributes(self, inverse_attributes): ... @@ -859,7 +865,13 @@ class file: @staticmethod def traverse_breadth_first(instance, max_level): ... def try_read_semicolon(self): ... - def types(self): ... + def types(self) -> tuple[str, ...]: + """Return a tuple of classes present in the file. + + E.g. `("IfcWallType", "IfcWall", "IfcArbitraryClosedProfileDef", ...)`. + """ + ... + def types_begin(self): ... def types_end(self): ... def unbatch(self): ... @@ -1000,6 +1012,7 @@ class matrix4(item): def translation_part(self): ... class named_type(parameter_type): + def _is(self, *args): ... def as_named_type(self): ... def declared_type(self): ... @@ -1026,6 +1039,7 @@ class offset_function(function_item): def start(self): ... class parameter_type: + def _is(self, *args): ... def as_aggregation_type(self): ... def as_named_type(self): ... def as_simple_type(self): ... @@ -1105,8 +1119,8 @@ class revolve(sweep): def matrix(self): ... class schema_definition: - def declaration_by_name(self, *args): ... - def declarations(self): ... + def declaration_by_name(self, *args: str) -> declaration: ... + def declarations(self) -> tuple[declaration, ...]: ... def entities(self): ... def enumeration_types(self): ... def instantiate(self, decl, data): ... @@ -1413,7 +1427,7 @@ def parse_ifcxml(filename): ... def polygons_to_svg(*args): ... def read(data): ... def register_schema(arg1): ... -def schema_by_name(arg1): ... +def schema_by_name(arg1: str) -> schema_definition: ... def schema_names(): ... def serialise(schema_name, shape_str, advanced): ... def set_feature(x, v): ... diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index 059312f89d..b634edab31 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -73,7 +73,7 @@ def get_declaration(element: ifcopenshell.entity_instance): return element.wrapped_data.declaration().as_entity() -def is_a(declaration: ifcopenshell.ifcopenshell_wrapper.entity, ifc_class: str) -> bool: +def is_a(declaration: ifcopenshell.ifcopenshell_wrapper.declaration, ifc_class: str) -> bool: """Checks if a schema declaration is a class :param declaration: The declaration from the schema. diff --git a/src/ifcopenshell-python/ifcopenshell/util/scripts/validate_stub.py b/src/ifcopenshell-python/ifcopenshell/util/scripts/validate_stub.py index 495eab0341..14b05ed258 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/scripts/validate_stub.py +++ b/src/ifcopenshell-python/ifcopenshell/util/scripts/validate_stub.py @@ -57,7 +57,7 @@ def get_function_node_name(node: ast.FunctionDef) -> Union[SubnameType, None]: :return: Function node name as ``SubnameType`` or ``None``, if function wasn't processed and can be skipped. """ node_name = node.name - if node_name.startswith("_"): + if node_name.startswith("_") and node_name not in ("_is",): return None args = [a.arg for a in node.args.args] if node.args.vararg: