diff --git a/src/bonsai/bonsai/tool/brick.py b/src/bonsai/bonsai/tool/brick.py
index 31a607f7f1..902fa50439 100644
--- a/src/bonsai/bonsai/tool/brick.py
+++ b/src/bonsai/bonsai/tool/brick.py
@@ -31,6 +31,7 @@ import ifcopenshell.guid
import ifcopenshell.util.brick
import ifcopenshell.util.element
import ifcopenshell.util.system
+from brickschema.persistent import Changeset
import bonsai.core.brick
import bonsai.core.tool
@@ -580,7 +581,7 @@ class BrickStore:
@classmethod
@contextmanager
- def new_changeset(cls) -> Generator[Any, None, None]:
+ def new_changeset(cls) -> Generator[Changeset]:
cls.current_changesets += 1
with BrickStore.graph.new_changeset("PROJECT") as cs:
yield cs
diff --git a/src/ifcopenshell-python/ifcopenshell/api/unit/add_context_dependent_unit.py b/src/ifcopenshell-python/ifcopenshell/api/unit/add_context_dependent_unit.py
index f9c76f9072..a169f49c4b 100644
--- a/src/ifcopenshell-python/ifcopenshell/api/unit/add_context_dependent_unit.py
+++ b/src/ifcopenshell-python/ifcopenshell/api/unit/add_context_dependent_unit.py
@@ -15,14 +15,21 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see .
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
import ifcopenshell
+if TYPE_CHECKING:
+ from ifcopenshell.util.unit import DimensionalExponents
+
def add_context_dependent_unit(
file: ifcopenshell.file,
unit_type: str = "USERDEFINED",
name: str = "THINGAMAJIG",
- dimensions: tuple[int, int, int, int, int, int, int] = (0, 0, 0, 0, 0, 0, 0),
+ dimensions: DimensionalExponents = (0, 0, 0, 0, 0, 0, 0),
) -> ifcopenshell.entity_instance:
"""Add a new arbitrary unit that can only be interpreted in a project specific context
diff --git a/src/ifcopenshell-python/ifcopenshell/sql.py b/src/ifcopenshell-python/ifcopenshell/sql.py
index 2ae2824b32..ac44b34806 100644
--- a/src/ifcopenshell-python/ifcopenshell/sql.py
+++ b/src/ifcopenshell-python/ifcopenshell/sql.py
@@ -123,7 +123,7 @@ class sqlite(file):
# For creating C++ instances so that some of the calls here work
self.shadow_file = ifcopenshell.file(schema_identifier=self.schema)
# But we only create them once per type because we basically only need access to 'semi-static' such as get_attribute_category()
- self.instance_map = {}
+ self.instance_map: dict[str, ifcopenshell.entity_instance] = {}
self.cursor.execute("SELECT ifc_id, ifc_class FROM id_map")
self.id_map: dict[int, str] = {}
@@ -186,7 +186,7 @@ class sqlite(file):
"""Not supported for sqlite database."""
assert False, "Not supported for sqlite database."
- def _create_entity(self, type):
+ def _create_entity(self, type: str) -> ifcopenshell.entity_instance:
if inst := self.instance_map.get(type):
return inst
else:
@@ -348,6 +348,7 @@ class sqlite(file):
class sqlite_entity:
sqlite_wrapper: sqlite_wrapper
+ wrapped_data: ifcopenshell.entity_instance
def __init__(self, id: int, ifc_class: str, file: sqlite = None):
if not ifc_class:
diff --git a/src/ifcopenshell-python/ifcopenshell/stream.py b/src/ifcopenshell-python/ifcopenshell/stream.py
index ae6651852f..2898f28c8a 100644
--- a/src/ifcopenshell-python/ifcopenshell/stream.py
+++ b/src/ifcopenshell-python/ifcopenshell/stream.py
@@ -188,13 +188,13 @@ try:
# For creating C++ instances so that some of the calls here work
self.shadow_file = ifcopenshell.file(schema=self.schema)
# But we only create them once per type because we basically only need access to 'semi-static' such as get_attribute_category()
- self.instance_map = {}
+ self.instance_map: dict[str, ifcopenshell.entity_instance] = {}
offset += len(line) + newline_character
self.preprocess_schema()
- def _create_entity(self, type):
+ def _create_entity(self, type: str) -> ifcopenshell.entity_instance:
if inst := self.instance_map.get(type):
return inst
else:
@@ -328,6 +328,7 @@ try:
class stream_entity:
stream_wrapper: stream_wrapper
+ wrapped_data: ifcopenshell.entity_instance
def __init__(self, id: int, ifc_class: str, file: stream = None):
if not ifc_class:
diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py
index c7761b9b48..07ca6d6d6a 100644
--- a/src/ifcopenshell-python/ifcopenshell/util/unit.py
+++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py
@@ -16,14 +16,19 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see .
+from __future__ import annotations
+
from collections.abc import Generator
from fractions import Fraction
from math import pi
-from typing import Literal, Optional, Union
+from typing import TYPE_CHECKING, Literal, Optional, TypeAlias, Union
import ifcopenshell
import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper
+if TYPE_CHECKING:
+ DimensionalExponents: TypeAlias = tuple[int, int, int, int, int, int, int]
+
prefixes = {
"EXA": 1e18,
"PETA": 1e15,
@@ -76,7 +81,7 @@ unit_names = [
"WEBER",
]
-si_dimensions = {
+si_dimensions: dict[str, DimensionalExponents] = {
"METRE": (1, 0, 0, 0, 0, 0, 0),
"SQUARE_METRE": (2, 0, 0, 0, 0, 0, 0),
"CUBIC_METRE": (3, 0, 0, 0, 0, 0, 0),
@@ -146,7 +151,7 @@ si_type_names = {
# See IfcDimensionalExponents:
# (Length, Mass, Time, ElectricCurrent, ThermodynamicTemperature, AmountOfSubstance, LuminousIntensity)
-named_dimensions = {
+named_dimensions: dict[str, DimensionalExponents] = {
"ABSORBEDDOSEUNIT": (2, 0, -2, 0, 0, 0, 0),
"AMOUNTOFSUBSTANCEUNIT": (0, 0, 0, 0, 0, 1, 0),
"AREAUNIT": (2, 0, 0, 0, 0, 0, 0),
@@ -398,15 +403,15 @@ def get_full_unit_name(unit: ifcopenshell.entity_instance) -> str:
return prefix + unit.Name.upper()
-def get_si_dimensions(name):
+def get_si_dimensions(name: str) -> DimensionalExponents:
return si_dimensions.get(name, si_dimensions["OTHERWISE"])
-def get_named_dimensions(name):
+def get_named_dimensions(name: str) -> DimensionalExponents:
return named_dimensions.get(name, (0, 0, 0, 0, 0, 0, 0))
-def get_unit_dimensions(unit: ifcopenshell.entity_instance) -> tuple[int, int, int, int, int, int, int]:
+def get_unit_dimensions(unit: ifcopenshell.entity_instance) -> DimensionalExponents:
"""Get the dimensional exponents of a unit, per IfcDimensionalExponents.
Supports IfcSIUnit, IfcConversionBasedUnit, IfcContextDependentUnit, and