Skip to content

Commit 8f91271

Browse files
authored
Replacing typish with runtype (#1967)
* Initial commit with bulk replace of typish * Created wrapped instance_of in utils * Fixed typing for mypy
1 parent 372ae55 commit 8f91271

12 files changed

Lines changed: 38 additions & 17 deletions

File tree

cadquery/assembly.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
get_args,
1313
)
1414
from typing_extensions import Literal, Self
15-
from typish import instance_of
1615
from uuid import uuid1 as uuid
1716
from warnings import warn
1817
from itertools import chain
@@ -39,7 +38,7 @@
3938
from .occ_impl.importers.assembly import importStep as _importStep, importXbf, importXml
4039

4140
from .selectors import _expression_grammar as _selector_grammar
42-
from .utils import deprecate, BiDict
41+
from .utils import deprecate, BiDict, instance_of
4342

4443
# type definitions
4544
AssemblyObjects = Union[Shape, Workplane, None]

cadquery/fig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from itertools import chain
1111
from webbrowser import open_new_tab
1212

13-
from typish import instance_of
14-
1513
from trame.app import get_server
1614
from trame.app.core import Server
1715
from trame.widgets import html, vtk as vtk_widgets, client
@@ -33,6 +31,8 @@
3331

3432
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera
3533

34+
from .utils import instance_of
35+
3636
FULL_SCREEN = "position:absolute; left:0; top:0; width:100vw; height:100vh;"
3737

3838

cadquery/occ_impl/solver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
Literal,
1010
cast as tcast,
1111
Type,
12+
get_origin,
1213
)
1314

1415
from math import radians, pi
15-
from typish import instance_of, get_type
1616

1717
import casadi as ca
1818

@@ -33,6 +33,7 @@
3333
from .geom import Location, Vector, Plane
3434
from .shapes import Shape, Face, Edge, Wire
3535
from ..types import Real
36+
from ..utils import instance_of
3637

3738
# type definitions
3839

@@ -179,7 +180,7 @@ def _validate(self, args: Tuple[Shape, ...], kind: ConstraintKind, param: Any):
179180
# check parameter
180181
if not instance_of(param, param_type) and param is not None:
181182
raise ValueError(
182-
f"Unsupported argument types {get_type(param)}, required {param_type}."
183+
f"Unsupported argument types {get_origin(param)}, required {param_type}."
183184
)
184185

185186
# check parameter conversion

cadquery/sketch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
cast as tcast,
1414
Literal,
1515
overload,
16+
get_origin,
1617
)
1718

1819
from math import tan, sin, cos, pi, radians, remainder
1920
from itertools import product, chain
2021
from multimethod import multimethod
21-
from typish import instance_of, get_type
2222

2323
from .hull import find_hull
2424
from .selectors import StringSyntaxSelector, Selector
2525
from .types import Real
26-
from .utils import get_arity
26+
from .utils import get_arity, instance_of
2727

2828
from .occ_impl.shapes import (
2929
Shape,
@@ -117,7 +117,7 @@ def __init__(
117117

118118
if not instance_of(param, param_type):
119119
raise ValueError(
120-
f"Unsupported argument types {get_type(param)}, required {param_type}."
120+
f"Unsupported argument types {get_origin(param)}, required {param_type}."
121121
)
122122

123123
# if all is fine store everything and possibly convert the params

cadquery/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import wraps
22
from inspect import signature, isbuiltin
3-
from typing import TypeVar, Callable, cast
3+
from typing import TypeVar, Callable, cast, Any
4+
from runtype import isa
45
from warnings import warn
56
from collections import UserDict
67

@@ -116,3 +117,11 @@ def __setitem__(self, k: K, v: V):
116117
def inv(self) -> dict[V, list[K]]:
117118

118119
return self._inv
120+
121+
122+
def instance_of(obj: object, *args: object) -> bool:
123+
"""
124+
Replacement for the instance_of method of typish, which
125+
now uses the isa method of the runtype package.
126+
"""
127+
return isa(obj, cast(tuple[type[Any], ...], args))

cadquery/vis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
from typing import Union, Any, List, Tuple, Iterable, cast, Optional
1616

17-
from typish import instance_of
18-
1917
from OCP.TopoDS import TopoDS_Shape
2018
from OCP.Geom import Geom_BSplineSurface
2119

@@ -39,6 +37,7 @@
3937
from vtkmodules.vtkCommonColor import vtkNamedColors
4038
from vtkmodules.vtkIOImage import vtkPNGWriter
4139

40+
from .utils import instance_of
4241

4342
DEFAULT_COLOR = (1, 0.8, 0)
4443
DEFAULT_EDGE_COLOR = (0, 0, 0)

conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ requirements:
2525
- nlopt
2626
- multimethod >=1.11,<2.0
2727
- casadi
28-
- typish
28+
- runtype
2929
- trame
3030
- trame-vtk
3131

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
- nlopt
1919
- path
2020
- casadi
21-
- typish
21+
- runtype
2222
- multimethod >=1.11,<2.0
2323
- typed-ast
2424
- regex

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ignore_missing_imports = True
3131
[mypy-docutils.*]
3232
ignore_missing_imports = True
3333

34-
[mypy-typish.*]
34+
[mypy-runtype.*]
3535
ignore_missing_imports = True
3636

3737
[mypy-casadi.*]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"ezdxf>=1.3.0",
3131
"multimethod>=1.11,<2.0",
3232
"nlopt>=2.9.0,<3.0",
33-
"typish",
33+
"runtype",
3434
"casadi",
3535
"path",
3636
"trame",

0 commit comments

Comments
 (0)