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 tempfile
from pathlib import Path
from typing import Optional
from typing import Optional, Union
import ifcopenshell.util.file
if hasattr(os, "uname"):
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:
from . import ifcopenshell_wrapper
except Exception as e:
if int(python_version_tuple[0]) == 2:
# Only for py2, as py3 has exception chaining
import traceback
traceback.print_exc()
print("-" * 64)
except Exception:
raise ImportError("IfcOpenShell not built for '%s'" % python_distribution)
from . import guid
from .file import file
from .entity_instance import entity_instance, register_schema_attributes
from .sql import sqlite, sqlite_entity
@@ -92,11 +84,12 @@ class SchemaError(Error):
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
You can specify a file format. If no format is given, it is guessed from its extension.
Currently supported specified format : .ifc | .ifcZIP | .ifcXML
You can specify a file format. If no format is given, it is guessed from
its extension. Currently supported specified format: .ifc | .ifcZIP |
.ifcXML.
You can then filter by element ID, class, etc, and subscript by id or guid.
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.guid
from typing import Optional
@@ -148,7 +148,7 @@ class tree(ifcopenshell_wrapper.tree):
def select(
self,
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,
) -> list[entity_instance]:
@@ -30,7 +30,7 @@ class Clipping:
operand_type: str = "IfcHalfSpaceSolid"
@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
`raw_data` can be either:
@@ -23,12 +23,12 @@ import ifcopenshell.util.schema
import ifcopenshell.util.type
from ifcopenshell.entity_instance import entity_instance
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
if schema not in templates:
templates[schema] = PsetQto(schema)