More cleaning up of forward type hints to fix import errors

This commit is contained in:
Dion Moult
2024-05-07 14:58:12 +10:00
parent 89c4cbeb05
commit 424a06f6c8
5 changed files with 12 additions and 18 deletions
@@ -35,9 +35,8 @@ import sys
import zipfile import zipfile
import tempfile import tempfile
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional, Union
import ifcopenshell.util.file
if hasattr(os, "uname"): if hasattr(os, "uname"):
platform_system = os.uname()[0].lower() platform_system = os.uname()[0].lower()
@@ -56,16 +55,9 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "lib", p
try: try:
from . import ifcopenshell_wrapper from . import ifcopenshell_wrapper
except Exception as e: except Exception:
if int(python_version_tuple[0]) == 2:
# Only for py2, as py3 has exception chaining
import traceback
traceback.print_exc()
print("-" * 64)
raise ImportError("IfcOpenShell not built for '%s'" % python_distribution) raise ImportError("IfcOpenShell not built for '%s'" % python_distribution)
from . import guid
from .file import file from .file import file
from .entity_instance import entity_instance, register_schema_attributes from .entity_instance import entity_instance, register_schema_attributes
from .sql import sqlite, sqlite_entity from .sql import sqlite, sqlite_entity
@@ -92,11 +84,12 @@ class SchemaError(Error):
pass pass
def open(path: "os.PathLike | str", format: str = None, should_stream: bool = False) -> file: def open(path: Union[os.PathLike, str], format: Optional[str] = None, should_stream: bool = False) -> file:
"""Loads an IFC dataset from a filepath """Loads an IFC dataset from a filepath
You can specify a file format. If no format is given, it is guessed from its extension. You can specify a file format. If no format is given, it is guessed from
Currently supported specified format : .ifc | .ifcZIP | .ifcXML its extension. Currently supported specified format: .ifc | .ifcZIP |
.ifcXML.
You can then filter by element ID, class, etc, and subscript by id or guid. You can then filter by element ID, class, etc, and subscript by id or guid.
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.guid
from typing import Optional from typing import Optional
@@ -148,7 +148,7 @@ class tree(ifcopenshell_wrapper.tree):
def select( def select(
self, self,
value: Union[ value: Union[
entity_instance, ifcopenshell_wrapper.BRepElement, tuple[float, float, float], TopoDS.TopoDS_Shape entity_instance, ifcopenshell_wrapper.BRepElement, tuple[float, float, float], "TopoDS.TopoDS_Shape"
], ],
**kwargs, **kwargs,
) -> list[entity_instance]: ) -> list[entity_instance]:
@@ -30,7 +30,7 @@ class Clipping:
operand_type: str = "IfcHalfSpaceSolid" operand_type: str = "IfcHalfSpaceSolid"
@classmethod @classmethod
def parse(cls, raw_data: Any) -> Union[ifcopenshell.entity_instance, Clipping, None]: def parse(cls, raw_data: Any) -> Union[ifcopenshell.entity_instance, "Clipping", None]:
"""Parse various formats into a clipping object """Parse various formats into a clipping object
`raw_data` can be either: `raw_data` can be either:
@@ -23,12 +23,12 @@ import ifcopenshell.util.schema
import ifcopenshell.util.type import ifcopenshell.util.type
from ifcopenshell.entity_instance import entity_instance from ifcopenshell.entity_instance import entity_instance
from functools import lru_cache from functools import lru_cache
from typing import List, Generator, Optional from typing import List, Optional
templates: dict[str, PsetQto] = {} templates: dict[str, "PsetQto"] = {}
def get_template(schema: str) -> PsetQto: def get_template(schema: str) -> "PsetQto":
global templates global templates
if schema not in templates: if schema not in templates:
templates[schema] = PsetQto(schema) templates[schema] = PsetQto(schema)