From 86bef0a25457b9a7cf236d0980fa4e15de54d63a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 23 Mar 2026 19:16:51 +0500 Subject: [PATCH] typing --- .../bonsai/bim/module/project/operator.py | 2 +- .../ifcopenshell/__init__.py | 20 ++++++++++--------- .../ifcopenshell/ifcopenshell_wrapper.pyi | 12 +++++------ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index e674cb56f4..e24f6f41d8 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -1102,7 +1102,7 @@ class LoadProject(bpy.types.Operator, IFCFileSelector, ImportHelper): else: return self.finish_loading_project(context) - def finish_loading_project(self, context): + def finish_loading_project(self, context: bpy.types.Context) -> set["rna_enums.OperatorReturnItems"]: try: filepath = self.get_filepath() if not self.is_existing_ifc_file(): diff --git a/src/ifcopenshell-python/ifcopenshell/__init__.py b/src/ifcopenshell-python/ifcopenshell/__init__.py index 51638f6954..6398c98842 100644 --- a/src/ifcopenshell-python/ifcopenshell/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/__init__.py @@ -131,17 +131,17 @@ class SchemaError(Error): @overload def open( - path: Union[os.PathLike, str], format: Optional[str] = None, *, should_stream: Literal[False] = False + path: Union[os.PathLike, str], format: SupportedFormat = None, *, should_stream: Literal[False] = False ) -> Union[_file, sqlite]: ... @overload -def open(path: Union[os.PathLike, str], format: Optional[str] = None, *, should_stream: Literal[True]) -> _stream: ... +def open(path: Union[os.PathLike, str], format: SupportedFormat = None, *, should_stream: Literal[True]) -> _stream: ... @overload def open( - path: Union[os.PathLike, str], format: Optional[str] = None, *, should_stream: bool = False, readonly: bool = False + path: Union[os.PathLike, str], format: SupportedFormat = None, *, should_stream: bool = False, readonly: bool = False ) -> Union[_file, sqlite, _stream]: ... def open( path: Union[os.PathLike, str], - format: Optional[str] = None, + format: SupportedFormat = None, should_stream: bool = False, readonly: bool = False, mmap: bool = False, @@ -153,8 +153,7 @@ def open( for reading large files. You can specify a file format. If no format is given, it is guessed from - its extension. Currently supported specified format: .ifc | .ifcZIP | - .ifcXML. + its extension. You can then filter by element ID, class, etc, and subscript by id or guid. @@ -200,12 +199,12 @@ def open( f.bypass_type(ty) if mmap: # mmap parameter is only available for builds with USE_MMAP, not used in our main builds - f.initialize(str(path.absolute()), mmap=mmap) # type: ignore[unknown-argument] + f.initialize(str(path.absolute()), mmap=mmap) # ty: ignore[unknown-argument] else: f.initialize(str(path.absolute())) elif mmap: # mmap parameter is only available for builds with USE_MMAP, not used in our main builds - f = ifcopenshell_wrapper.open(str(path.absolute()), mmap=mmap) # type: ignore[unknown-argument] + f = ifcopenshell_wrapper.open(str(path.absolute()), mmap=mmap) # ty: ignore[unknown-argument] else: f = ifcopenshell_wrapper.open(str(path.absolute())) return file(f) @@ -288,7 +287,10 @@ def schema_by_name( return ifcopenshell_wrapper.schema_by_name(schema) -def guess_format(path: Path) -> Literal[".ifc", ".ifcZIP", ".ifcXML", ".ifcJSON", ".ifcSQLite", None]: +SupportedFormat = Literal[".ifc", ".ifcZIP", ".ifcXML", ".ifcJSON", ".ifcSQLite", "rocksdb", None] + + +def guess_format(path: Path) -> SupportedFormat: """Guesses the IFC format using file extension IFCs may be serialised as different formats. The most common is a ``.ifc`` diff --git a/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi b/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi index b2f868ec24..28caafc262 100644 --- a/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi +++ b/src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.pyi @@ -434,10 +434,10 @@ class RocksDBPrefixIterator: class RocksDbSerializer: def __init__(self, *args): ... - def finalize(self): ... - def ready(self): ... - def setFile(self, arg2): ... - def writeHeader(self): ... + def finalize(self) -> None: ... + def ready(self) -> bool: ... + def setFile(self, arg2) -> None: ... + def writeHeader(self) -> None: ... class Serialization(Representation): def __init__(self, brep): ... @@ -1008,7 +1008,7 @@ class file: def by_id(self, id: int) -> entity_instance: ... def by_type(self, *args): ... def by_type_excl_subtypes(self, *args): ... - def bypass_type(self, type_name): ... + def bypass_type(self, type_name: str) -> None: ... calculate_unit_factors: bool check_existance_before_adding: bool def create(self, decl): ... @@ -1717,7 +1717,7 @@ def line_segments_to_polygons(s, eps, segments): ... def map_shape(settings, instance): ... def nary_union(sequence): ... def new_IfcBaseClass(schema_identifier: str, name: str) -> entity_instance: ... -def open(fn, readonly=False): ... +def open(fn: str, readonly: bool = False) -> file: ... def parse_ifcxml(filename): ... def polygons_to_svg(*args): ... def read(data): ...