diff --git a/src/ifcopenshell-python/ifcopenshell/__init__.py b/src/ifcopenshell-python/ifcopenshell/__init__.py index e3f7fd0b25..a0662f24cc 100644 --- a/src/ifcopenshell-python/ifcopenshell/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/__init__.py @@ -135,7 +135,7 @@ def open( def open(path: Union[os.PathLike, str], format: Optional[str] = None, *, should_stream: Literal[True]) -> _stream: ... @overload def open( - path: Union[os.PathLike, str], format: Optional[str] = None, *, should_stream: bool + path: Union[os.PathLike, str], format: Optional[str] = None, *, should_stream: bool = False, readonly: bool = False ) -> Union[_file, sqlite, _stream]: ... def open( path: Union[os.PathLike, str], format: Optional[str] = None, should_stream: bool = False, readonly: bool = False diff --git a/src/ifcopenshell-python/test/typing_tests.py b/src/ifcopenshell-python/test/typing_tests.py new file mode 100644 index 0000000000..5e2a14fd39 --- /dev/null +++ b/src/ifcopenshell-python/test/typing_tests.py @@ -0,0 +1,39 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Thomas Krijnen +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . +"""Typing tests for ifcopenshell. + +This file should produce no warnings from type checker (currently pyright). +Those tests are not automatically checked and just there to make sure overloads are making sense. +""" + + +import ifcopenshell +from typing import assert_type, Union + + +def ifcopenshell_open_test(str_: str, bool_: bool): + ifc_file = ifcopenshell.open(str_) + assert_type(ifc_file, Union[ifcopenshell.file, ifcopenshell.sqlite]) + + ifc_file = ifcopenshell.open(str_, should_stream=bool_) + assert_type(ifc_file, Union[ifcopenshell.file, ifcopenshell.sqlite, ifcopenshell.stream]) + + ifc_file = ifcopenshell.open(str_, should_stream=True) + assert_type(ifc_file, ifcopenshell.stream) + + ifc_file = ifcopenshell.open(str_, readonly=True)