CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.26k stars 295 forks source link

Multimethod 1.10 causes issues [was: 'sweep' end in 'TypeError: typing_extensions.Literal cannot be used with isinstance()'] #1431

Open mryndzionek opened 1 year ago

mryndzionek commented 1 year ago

Simple example:

import cadquery as cq

r = 0.5  # Radius of the helix
p = 0.4  # Pitch of the helix - vertical distance between loops
h = 2.4  # Height of the helix - total height

# Helix
wire = cq.Wire.makeHelix(pitch=p, height=h, radius=r)
helix = cq.Workplane(obj=wire)

# Final result: A 2D shape swept along a helix.
result = (
    cq.Workplane("XZ")  # helix is moving up the Z axis
    .center(r, 0)  # offset rect
    .rect(0.15, 0.15)
    .sweep(helix, isFrenet=True)  # Frenet keeps orientation as expected
)

show_object(result)

ends with:

Traceback (most recent call last):
  File "/cq-editor/lib/python3.9/site-packages/cq_cli/main.py", line 36, in build_and_parse
    raise (build_result.exception)
  File "/cq-editor/lib/python3.9/site-packages/cadquery/cqgi.py", line 119, in build
    exec(c, env)
  File "<cqscript>", line 32, in <module>
  File "/cq-editor/lib/python3.9/site-packages/cadquery/cq.py", line 3196, in sweep
    r = self._sweep(
  File "/cq-editor/lib/python3.9/site-packages/cadquery/cq.py", line 3804, in _sweep
    thisObj = Solid.sweep(f, p, makeSolid, isFrenet, mode, transition)
  File "/cq-editor/lib/python3.9/site-packages/cadquery/utils.py", line 50, in __call__
    return super().__call__(*args, **kwargs)
  File "/cq-editor/lib/python3.9/site-packages/multimethod/__init__.py", line 326, in __call__
    func = self[tuple(func(arg) for func, arg in zip(self.type_checkers, args))]
  File "/cq-editor/lib/python3.9/site-packages/multimethod/__init__.py", line 326, in <genexpr>
    func = self[tuple(func(arg) for func, arg in zip(self.type_checkers, args))]
  File "/cq-editor/lib/python3.9/site-packages/multimethod/__init__.py", line 131, in get_type
    if not isinstance(arg, self.__origin__):  # no need to check subscripts
  File "/usr/lib/python3.9/typing.py", line 338, in __instancecheck__
    raise TypeError(f"{self} cannot be used with isinstance()")
TypeError: typing_extensions.Literal cannot be used with isinstance()
jmwright commented 1 year ago

I am not able to reproduce this error. What version of CadQuery are you running, and how did you install it?

mryndzionek commented 1 year ago

I am not able to reproduce this error. What version of CadQuery are you running, and how did you install it?

2.3.1, installed using pip. Tested on Python 3.8 and 3.9.

jmwright commented 1 year ago

Ok, I can reproduce with CadQuery 2.3.1, but cannot with the latest git version, so it has been fixed. I don't have time to track down exactly where right now, but I'm guessing it was during the rework of topology traversal.

Can you install CadQuery from git and try again?

mryndzionek commented 1 year ago

Ok, I can reproduce with CadQuery 2.3.1, but cannot with the latest git version, so it has been fixed. I don't have time to track down exactly where right now, but I'm guessing it was during the rework of topology traversal.

Can you install CadQuery from git and try again?

I installed using:

pip install git+https://github.com/CadQuery/cadquery.git

Reported version is: 2.4.0.dev0, but I still hit the same error.

adam-urbanczyk commented 1 year ago

Could you maybe specify your env completely?

jmwright commented 1 year ago

Your code above has show_object. Are you running it in CQ-editor? If so, how did you install it? It could be running the version of CQ that was bundled with CQ-editor.

mryndzionek commented 1 year ago

Could you maybe specify your env completely?

What exactly do you need? I've installed CQ-Editor in a fresh venv. Added:

    install_requires=[
        "logbook>=1",
        "path>=16",
        "PyQt5>=5",
        "pyqtgraph==0.12",
        "requests>=2,<3",
        "spyder>=5,<6")

to setup.py.

mryndzionek commented 1 year ago

Your code above has show_object. Are you running it in CQ-editor? If so, how did you install it? It could be running the version of CQ that was bundled with CQ-editor.

Yes, I'm running in CQ-editor. Fresh install in clean venv. I'm printing version from my script, so pretty sure CQ-editor uses 2.4.0.dev0. I also tried cq-cli - same error.

adam-urbanczyk commented 1 year ago

Could you maybe specify your env completely?

What exactly do you need? I've installed CQ-Editor in a fresh venv. Added:

This conda list or this pip list.

mryndzionek commented 1 year ago

Could you maybe specify your env completely?

What exactly do you need? I've installed CQ-Editor in a fresh venv. Added:

This conda list or this pip list.

pip_list.txt

adam-urbanczyk commented 1 year ago

Does downgrading multimethod to 1.9.1 solve the issue?

mryndzionek commented 1 year ago

Does downgrading multimethod to 1.9.1 solve the issue?

Okay, yes, it does. Thanks!

jmwright commented 1 year ago

@adam-urbanczyk Do we need to change the conda and pip version pins for now?

adam-urbanczyk commented 1 year ago

Yes, I think so

adam-urbanczyk commented 1 year ago

@mryndzionek I cannot reproduce your issue locally.

mryndzionek commented 1 year ago

@mryndzionek I cannot reproduce your issue locally.

What can I say, I posted the 'pip list' above. With this environment I definitely hit the error.

adam-urbanczyk commented 1 year ago

I do get a regression on the tests though, so there is some kind of problem.

lorenzncode commented 1 year ago

I can reproduce the error with a Python 3.9.18 env:

(mm110py39) [lorenzn@fedora tmp]$ python test.py 

Traceback (most recent call last):
  File "/tmp/test.py", line 15, in 
    cq.Workplane("XZ")  # helix is moving up the Z axis
  File "/home/lorenzn/tools/mambaforge_230901/envs/mm110py39/lib/python3.9/site-packages/cadquery/cq.py", line 3196, in sweep
    r = self._sweep(
  File "/home/lorenzn/tools/mambaforge_230901/envs/mm110py39/lib/python3.9/site-packages/cadquery/cq.py", line 3804, in _sweep
    thisObj = Solid.sweep(f, p, makeSolid, isFrenet, mode, transition)
  File "/home/lorenzn/tools/mambaforge_230901/envs/mm110py39/lib/python3.9/site-packages/cadquery/utils.py", line 50, in __call__
    return super().__call__(*args, **kwargs)
  File "/home/lorenzn/tools/mambaforge_230901/envs/mm110py39/lib/python3.9/site-packages/multimethod/__init__.py", line 326, in __call__
    func = self[tuple(func(arg) for func, arg in zip(self.type_checkers, args))]
  File "/home/lorenzn/tools/mambaforge_230901/envs/mm110py39/lib/python3.9/site-packages/multimethod/__init__.py", line 326, in 
    func = self[tuple(func(arg) for func, arg in zip(self.type_checkers, args))]
  File "/home/lorenzn/tools/mambaforge_230901/envs/mm110py39/lib/python3.9/site-packages/multimethod/__init__.py", line 131, in get_type
    if not isinstance(arg, self.__origin__):  # no need to check subscripts
  File "/home/lorenzn/tools/mambaforge_230901/envs/mm110py39/lib/python3.9/typing.py", line 347, in __instancecheck__
    raise TypeError(f"{self} cannot be used with isinstance()")
TypeError: typing_extensions.Literal cannot be used with isinstance()
(mm110py39) [lorenzn@fedora tmp]$ conda list 
# packages in environment at /home/lorenzn/tools/mambaforge_230901/envs/mm110py39:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
aiohttp                   3.8.6            py39hd1e30aa_1    conda-forge
aiosignal                 1.3.1              pyhd8ed1ab_0    conda-forge
alsa-lib                  1.2.8                h166bdaf_0    conda-forge
ampl-mp                   3.1.0             h2cc385e_1006    conda-forge
aom                       3.5.0                h27087fc_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
async-timeout             4.0.3              pyhd8ed1ab_0    conda-forge
attr                      2.5.1                h166bdaf_1    conda-forge
attrs                     23.1.0             pyh71513ae_1    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.5              pyhd8ed1ab_0    conda-forge
brotli                    1.1.0                hd590300_1    conda-forge
brotli-bin                1.1.0                hd590300_1    conda-forge
bzip2                     1.0.8                hd590300_5    conda-forge
c-ares                    1.21.0               hd590300_0    conda-forge
ca-certificates           2023.7.22            hbcca054_0    conda-forge
cadquery                  master          2.3.1_76_g7bc8c00    cadquery
cairo                     1.16.0            ha61ee94_1014    conda-forge
casadi                    3.6.3            py39h4b51453_1    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
curl                      8.1.2                h409715c_0    conda-forge
dbus                      1.13.6               h5008d03_3    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
double-conversion         3.2.0                h27087fc_1    conda-forge
eigen                     3.4.0                h00ab1b0_0    conda-forge
exceptiongroup            1.1.3              pyhd8ed1ab_0    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
expat                     2.5.0                hcb278e6_1    conda-forge
ezdxf                     1.1.0            py39hda80f44_1    conda-forge
ffmpeg                    5.1.2           gpl_h8dda1f0_106    conda-forge
fftw                      3.3.10          nompi_hc118613_108    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.44.0           py39hd1e30aa_0    conda-forge
freeimage                 3.18.0              hca5c823_12    conda-forge
freetype                  2.12.1               h267a509_2    conda-forge
frozenlist                1.4.0            py39hd1e30aa_1    conda-forge
gettext                   0.21.1               h27087fc_0    conda-forge
gl2ps                     1.4.2                h0708190_0    conda-forge
glew                      2.1.0                h9c3ff4c_2    conda-forge
glib                      2.78.1               hfc55251_0    conda-forge
glib-tools                2.78.1               hfc55251_0    conda-forge
gmp                       6.2.1                h58526e2_0    conda-forge
gnutls                    3.7.8                hf3e180e_0    conda-forge
graphite2                 1.3.13            h58526e2_1001    conda-forge
gst-plugins-base          1.22.0               h4243ec0_2    conda-forge
gstreamer                 1.22.0               h25f0c4b_2    conda-forge
gstreamer-orc             0.4.34               hd590300_0    conda-forge
harfbuzz                  6.0.0                h8e241bc_0    conda-forge
hdf4                      4.2.15               h9772cbc_5    conda-forge
hdf5                      1.12.2          nompi_h4df4325_101    conda-forge
icu                       70.1                 h27087fc_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
imath                     3.1.6                h6239696_1    conda-forge
ipopt                     3.14.12              he6d3896_1    conda-forge
ipython                   8.17.2             pyh41d4057_0    conda-forge
jack                      1.9.22               h11f4161_0    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h0b41bf4_3    conda-forge
jsoncpp                   1.9.5                h4bd325d_1    conda-forge
jxrlib                    1.1                  h7f98852_2    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.20.1               h81ceb04_0    conda-forge
lame                      3.100             h166bdaf_1003    conda-forge
lcms2                     2.15                 hfd0df8a_0    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libaec                    1.1.2                h59595ed_1    conda-forge
libblas                   3.9.0           19_linux64_openblas    conda-forge
libbrotlicommon           1.1.0                hd590300_1    conda-forge
libbrotlidec              1.1.0                hd590300_1    conda-forge
libbrotlienc              1.1.0                hd590300_1    conda-forge
libcap                    2.67                 he9d0100_0    conda-forge
libcblas                  3.9.0           19_linux64_openblas    conda-forge
libclang                  15.0.7          default_h7634d5b_3    conda-forge
libclang13                15.0.7          default_h9986a30_3    conda-forge
libcups                   2.3.3                h36d4200_3    conda-forge
libcurl                   8.1.2                h409715c_0    conda-forge
libdb                     6.2.32               h9c3ff4c_0    conda-forge
libdeflate                1.17                 h0b41bf4_0    conda-forge
libdrm                    2.4.114              h166bdaf_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libevent                  2.1.10               h28343ad_4    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libflac                   1.4.3                h59595ed_0    conda-forge
libgcc-ng                 13.2.0               h807b86a_2    conda-forge
libgcrypt                 1.10.2               hd590300_0    conda-forge
libgfortran-ng            13.2.0               h69a702a_2    conda-forge
libgfortran5              13.2.0               ha4646dd_2    conda-forge
libglib                   2.78.1               hebfc3b9_0    conda-forge
libglu                    9.0.0             he1b5a44_1001    conda-forge
libgomp                   13.2.0               h807b86a_2    conda-forge
libgpg-error              1.47                 h71f35ed_0    conda-forge
libhwloc                  2.9.1                hd6dc26d_0    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
libidn2                   2.3.4                h166bdaf_0    conda-forge
liblapack                 3.9.0           19_linux64_openblas    conda-forge
libllvm15                 15.0.7               hadd5161_1    conda-forge
libnetcdf                 4.9.1           nompi_h34a3ff0_101    conda-forge
libnghttp2                1.55.1               h47da74e_0    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libogg                    1.3.4                h7f98852_1    conda-forge
libopenblas               0.3.24          pthreads_h413a1c8_0    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libosqp                   0.6.3                h59595ed_0    conda-forge
libpciaccess              0.17                 h166bdaf_0    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
libpq                     15.3                 hbcd7760_1    conda-forge
libqdldl                  0.1.5                h27087fc_1    conda-forge
libraw                    0.21.1               h89bc310_0    conda-forge
libsndfile                1.2.2                hc60ed4a_1    conda-forge
libspral                  2023.08.02           h2baf039_0    conda-forge
libsqlite                 3.44.0               h2797004_0    conda-forge
libssh2                   1.11.0               h0841786_0    conda-forge
libstdcxx-ng              13.2.0               h7e041cc_2    conda-forge
libsystemd0               253                  h8c4010b_1    conda-forge
libtasn1                  4.19.0               h166bdaf_0    conda-forge
libtheora                 1.1.1             h7f98852_1005    conda-forge
libtiff                   4.5.0                h6adf6a1_2    conda-forge
libtool                   2.4.7                h27087fc_0    conda-forge
libudev1                  253                  h0b41bf4_1    conda-forge
libunistring              0.9.10               h7f98852_0    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libva                     2.18.0               h0b41bf4_0    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libvpx                    1.11.0               h9c3ff4c_3    conda-forge
libwebp-base              1.3.2                hd590300_0    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libxkbcommon              1.5.0                h79f4944_1    conda-forge
libxml2                   2.10.3               hca2bb57_4    conda-forge
libzip                    1.10.1               h2629f0a_3    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
loguru                    0.7.2            py39hf3d152e_1    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
metis                     5.1.0             h59595ed_1007    conda-forge
mpg123                    1.32.3               h59595ed_0    conda-forge
multidict                 6.0.4            py39hd1e30aa_1    conda-forge
multimethod               1.10                     pypi_0    pypi
mumps-include             5.2.1               ha770c72_11    conda-forge
mumps-seq                 5.2.1               h2104b81_11    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mysql-common              8.0.33               hf1915f5_6    conda-forge
mysql-libs                8.0.33               hca2cd23_6    conda-forge
ncurses                   6.4                  h59595ed_2    conda-forge
nettle                    3.8.1                hc379101_1    conda-forge
nlohmann_json             3.11.2               h27087fc_0    conda-forge
nlopt                     2.7.1            py39h74f0fd2_4    conda-forge
nptyping                  2.5.0              pyhd8ed1ab_0    conda-forge
nspr                      4.35                 h27087fc_0    conda-forge
nss                       3.94                 h1d7d5a4_0    conda-forge
numpy                     1.26.0           py39h474f0d3_0    conda-forge
occt                      7.7.1           all_h16763a6_201    conda-forge
ocp                       7.7.1.0          py39h256fbb3_1    conda-forge
openexr                   3.1.5                h0cdce71_2    conda-forge
openh264                  2.3.1                hcb278e6_2    conda-forge
openjpeg                  2.5.0                hfec8fc6_2    conda-forge
openssl                   3.1.4                hd590300_0    conda-forge
p11-kit                   0.24.1               hc5aa10d_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pcre2                     10.40                hc3806b6_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       23.3.1             pyhd8ed1ab_0    conda-forge
pixman                    0.42.2               h59595ed_0    conda-forge
proj                      9.1.1                h8ffa02c_2    conda-forge
prompt-toolkit            3.0.39             pyha770c72_0    conda-forge
prompt_toolkit            3.0.39               hd8ed1ab_0    conda-forge
proxsuite                 0.5.0            py39h7633fee_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pugixml                   1.11.4               h59595ed_1    conda-forge
pulseaudio                16.1                 hcb278e6_3    conda-forge
pulseaudio-client         16.1                 h5195f5e_3    conda-forge
pulseaudio-daemon         16.1                 ha8d29e2_3    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pygments                  2.16.1             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.1              pyhd8ed1ab_0    conda-forge
python                    3.9.18          h0755675_0_cpython    conda-forge
python_abi                3.9                      4_cp39    conda-forge
qt-main                   5.15.8               h5d23da1_6    conda-forge
rapidjson                 1.1.0             he1b5a44_1002    conda-forge
readline                  8.2                  h8228510_1    conda-forge
scipy                     1.11.3           py39h474f0d3_1    conda-forge
scotch                    6.0.9                hb2e6521_2    conda-forge
setuptools                68.2.2             pyhd8ed1ab_0    conda-forge
simde                     0.7.6                h00ab1b0_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.44.0               h2c6b66d_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
svt-av1                   1.4.1                hcb278e6_0    conda-forge
tbb                       2021.9.0             hf52228f_0    conda-forge
tbb-devel                 2021.9.0             hf52228f_0    conda-forge
tinyxml2                  9.0.0                h9c3ff4c_2    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
traitlets                 5.13.0             pyhd8ed1ab_0    conda-forge
typing-extensions         4.8.0                hd8ed1ab_0    conda-forge
typing_extensions         4.8.0              pyha770c72_0    conda-forge
typish                    1.9.3              pyhd8ed1ab_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
unicodedata2              15.1.0           py39hd1e30aa_0    conda-forge
unixodbc                  2.3.12               h661eb56_0    conda-forge
utfcpp                    4.0.1                ha770c72_0    conda-forge
vtk                       9.2.5           qt_py39hfb82713_203    conda-forge
wcwidth                   0.2.9              pyhd8ed1ab_0    conda-forge
wheel                     0.41.3             pyhd8ed1ab_0    conda-forge
wslink                    1.12.4             pyhd8ed1ab_0    conda-forge
x264                      1!164.3095           h166bdaf_2    conda-forge
x265                      3.5                  h924138e_3    conda-forge
xcb-util                  0.4.0                h516909a_0    conda-forge
xcb-util-image            0.4.0                h166bdaf_0    conda-forge
xcb-util-keysyms          0.4.0                h516909a_0    conda-forge
xcb-util-renderutil       0.3.9                h166bdaf_0    conda-forge
xcb-util-wm               0.4.1                h516909a_0    conda-forge
xkeyboard-config          2.38                 h0b41bf4_0    conda-forge
xorg-fixesproto           5.0               h7f98852_1002    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.0.10               h7f98852_0    conda-forge
xorg-libsm                1.2.3             hd9c2040_1000    conda-forge
xorg-libx11               1.8.4                h0b41bf4_0    conda-forge
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h0b41bf4_2    conda-forge
xorg-libxfixes            5.0.3             h7f98852_1004    conda-forge
xorg-libxrender           0.9.10            h7f98852_1003    conda-forge
xorg-libxt                1.3.0                hd590300_0    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-xextproto            7.3.0             h0b41bf4_1003    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yarl                      1.9.2            py39hd1e30aa_1    conda-forge
zlib                      1.2.13               hd590300_5    conda-forge
zstd                      1.5.5                hfc55251_0    conda-forge

I could not reproduce the error with Python 3.10.13, or 3.11.6 with multimethod 1.10.

I confirm I can also reproduce the failed tests/test_cadquery.py::TestCadQuery::testSweep with the multimethod 1.10 env (both the 3.10.13 and 3.11.6 envs).