Return support for creating uninitialized files from Python

Created a new method to avoid complicating `ifcopenshell.file` ctor signature.
This commit is contained in:
Andrej730
2026-08-03 13:46:58 +05:00
parent 26b412cff6
commit b1f388311c
3 changed files with 27 additions and 3 deletions
@@ -237,7 +237,7 @@ def open(
if readonly: # Temporary conditional see #7131. Remove once newer builds don't segfault on Linux.
f = ifcopenshell_wrapper.open(str(path.absolute()), readonly, *optional_logger_args(logger))
elif bypass_types:
f = ifcopenshell_wrapper.file(ifcopenshell_wrapper.uninitialized_tag(), *optional_logger_args(logger))
f = ifcopenshell_wrapper.file.create_uninitialized(*optional_logger_args(logger))
for ty in bypass_types:
f.bypass_type(ty)
if mmap:
@@ -845,6 +845,27 @@ class file(file_mixin):
schema_identifier: str | None = None,
schema_version: tuple[int, int, int, int] | None = None,
): ...
@staticmethod
def create_uninitialized(logger: logger | None = None) -> file:
"""Construct a file with no schema/data yet, to be populated by a later call to ``initialize()``.
When file is uninitialized, the only two available methods during
this state are ``bypass_type()`` and ``initialize()``.
"""
...
def bypass_type(self, type_name: str) -> None:
"""Skip loading instances of ``type_name``."""
...
# NOTE: inaccurate `*args` - not all args are `str`.
def initialize(self, *args: str) -> bool:
"""Parse a file on a ``create_uninitialized()`` instance.
:param args: ``args[0]`` is a string path to the IFC file.
:return: Whether the file was read and parsed successfully. On failure, check ``good()`` for the specific reason.
"""
...
def _add(self, entity: entity_instance, id: int = -1) -> entity_instance: ...
def add_type_ref(self, new_entity): ...
def batch(self) -> None:
@@ -873,7 +894,6 @@ class file(file_mixin):
def by_id(self, instance_id: int) -> entity_instance: ...
def _by_type(self, *args: declaration | str) -> tuple[entity_instance, ...]: ...
def _by_type_excl_subtypes(self, *args: declaration | str) -> tuple[entity_instance, ...]: ...
def bypass_type(self, type_name: str) -> None: ...
def create(self, *args) -> entity_instance: ...
@staticmethod
def create_timestamp() -> str: ...
@@ -910,7 +930,6 @@ class file(file_mixin):
@property
def header(self) -> spf_header: ...
def ifcroot_type(self) -> entity: ...
def initialize(self, *args): ...
def key_value_store_iter(self, prefix): ...
def key_value_store_query(self, key): ...
def recalculate_id_counter(self): ...