EnMAP-Box / enmap-box

EnMAP-Box source code repository. See https://enmap-box.readthedocs.io for documentation
GNU General Public License v3.0
35 stars 16 forks source link

TypeError: Subscripted generics cannot be used with class and instance checks #330

Closed danschef closed 1 year ago

danschef commented 1 year ago

When right-clicking on a raster layer listed in the "Data Sources" panel of the EnMAP-Box 3.11.1, only the following error pops up instead of showing a context menu:

An error has occurred while executing Python code: 

TypeError: Subscripted generics cannot be used with class and instance checks 
Traceback (most recent call last):
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/gui/datasources/manager.py", line 490, in contextMenuEvent
    appendRasterActions(sub, node, None)
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/gui/datasources/manager.py", line 479, in appendRasterActions
    for name, shortNames in CreateSpectralIndicesAlgorithm.sentinel2Visualizations().items():
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 904, in wrapper
    check_return_type(retval, memo)
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 713, in check_return_type
    raise exc from None
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 711, in check_return_type
    check_type('the return value', retval, memo.type_hints['return'], memo)
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 641, in check_type
    checker_func(argname, value, expected_type, memo)
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 310, in check_dict
    check_type('{}[{!r}]'.format(argname, k), v, value_type, memo)
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 641, in check_type
    checker_func(argname, value, expected_type, memo)
  File "/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 387, in check_tuple
    if not isinstance(value, expected_type):
  File "/home/gfz-fe/mambaforge/envs/enpt_full/lib/python3.10/typing.py", line 994, in __instancecheck__
    return self.__subclasscheck__(type(obj))
  File "/home/gfz-fe/mambaforge/envs/enpt_full/lib/python3.10/typing.py", line 997, in __subclasscheck__
    raise TypeError("Subscripted generics cannot be used with"
TypeError: Subscripted generics cannot be used with class and instance checks

Python version: 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:40:41) [GCC 10.4.0] 
QGIS version: 3.28.2-Firenze Firenze, exported 

Python Path:
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/apps/ensomap
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/Coregistration
/home/gfz-fe/mambaforge/envs/enpt_full/share/qgis/python
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins
/home/gfz-fe/mambaforge/envs/enpt_full/share/qgis/python/plugins
/home/gfz-fe/mambaforge/envs/enpt_full/share/qgis/python/plugins
/home/gfz-fe/mambaforge/envs/enpt_full/share/qgis/python
/home/gfz-fe
/home/gfz-fe/mambaforge/envs/enpt_full/lib/python310.zip
/home/gfz-fe/mambaforge/envs/enpt_full/lib/python3.10
/home/gfz-fe/mambaforge/envs/enpt_full/lib/python3.10/lib-dynload
/home/gfz-fe/mambaforge/envs/enpt_full/lib/python3.10/site-packages
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python
.
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/vrtbuilderplugin
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/vrtbuilderplugin/vrtbuilder
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/extlibs_linux
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/qgispluginsupport/qps/pyqtgraph
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/site-packages
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/apps
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/coreapps
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/eo4qapps
/home/gfz-fe/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/apps/lmuapps
janzandr commented 1 year ago

@jakimowb , @thielfab maybe this is related to Linux or Python 3.10, which I don't have on my system. Can one of you reproduce this?

jakimowb commented 1 year ago

@janzandr python 3.10 is available in an up-to-date conda installation

janzandr commented 1 year ago

I'll try the mambaforge installation recommended by @danschef: https://enmap.git-pages.gfz-potsdam.de/GFZ_Tools_EnMAP_BOX/EnPT/doc/installation.html#installing-enpt-along-with-qgis-and-the-enmap-box-backend-gui

janzandr commented 1 year ago

Alright, I can reproduce this inside the mambaforge environment.

janzandr commented 1 year ago

Needed to update the typeguard package, which we ship together with the EnMAP-Box (enmap-box/site-packages/typeguard). Old typeguard version wasn't playing nicely together with Python 3.10. Works now, after fixing some other failing typechecks related to the QgisInterface class. @jakimowb, we may encounter more of these failing typechecks at runtime in a Python 3.10 environment.

danschef commented 1 year ago

@janzandr Thanks for fixing! Would it be possible to have a bug-fix release for the EnMAP-Box 3.11 that includes this? 3.12 does not seem to be stable, yet, and we need a properly working version for the workshop in march.

Why do you actually ship typeguard together with the EnMAP-Box instead of just adding it to the requirements.txt? From my point of view, this will always lead into incompatibilities after some time, just because you use a frozen code base there.

janzandr commented 1 year ago

Why do you actually ship typeguard together with the EnMAP-Box instead of just adding it to the requirements.txt? From my point of view, this will always lead into incompatibilities after some time, just because you use a frozen code base there.

Yes, good point. @jakimowb, can't remember, was there a reason not adding it to the requirements.txt?

janzandr commented 1 year ago

Would it be possible to have a bug-fix release for the EnMAP-Box 3.11 that includes this? 3.12 does not seem to be stable, yet, and we need a properly working version for the workshop in march.

I released a dev-version that includes the fix: https://github.com/EnMAP-Box/enmap-box/releases/tag/v3.12-alpha.7

I would suggest having a v3.12 build for the workshop.

danschef commented 1 year ago

Thanks, but this is an Alpha version. I tested it last week and it did not seem to be stable so far. I would really like to have a 3.11.2 version that includes this fix, just to be sure we have something working - for the workshop but also to be able to test my tools in the next weeks.

janzandr commented 1 year ago

Thanks, but this is an Alpha version. I tested it last week

It's not the version from last week, I just uploaded it.

and it did not seem to be stable so far.

We still have time fixing stuff. Just report the stuff that isn't working. We prefere to work on the DEV version, because backporting is always more complicated. We usually only do backports for blocking/critical issues.

thielfab commented 1 year ago

Why do you actually ship typeguard together with the EnMAP-Box instead of just adding it to the requirements.txt? From my point of view, this will always lead into incompatibilities after some time, just because you use a frozen code base there.

Yes, good point. @jakimowb, can't remember, was there a reason not adding it to the requirements.txt?

I think the main reason was that the EnMAP-Box should start and work (basic functionality, GUI etc.) without the need of having dependencies installed. BTW. If I install your version from above in a fresh QGIS (Ubuntu docker) I get an ModuleNotFoundError: No module named 'typing_extensions' error.

janzandr commented 1 year ago

Hi @thielfab, please show full stacktrace.

thielfab commented 1 year ago
Couldn't load plugin 'enmapboxplugin' due to an error when calling its classFactory() method 

ModuleNotFoundError: No module named 'typing_extensions' 
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 423, in _startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/__init__.py", line 55, in classFactory
    raise ex
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/__init__.py", line 50, in classFactory
    from enmapbox.enmapboxplugin import EnMAPBoxPlugin
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/__init__.py", line 411, in 
    from enmapbox.gui.enmapboxgui import EnMAPBox
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/gui/enmapboxgui.py", line 27, in 
    from typeguard import typechecked
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 28, in 
    from ._checkers import (
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/_checkers.py", line 50, in 
    from typing_extensions import Any as SubclassableAny
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'typing_extensions'

Python version: 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] 
QGIS version: 3.28.2-Firenze Firenze, b47e00ba60 
janzandr commented 1 year ago

Looks like the 'typing_extensions' module is not part of your distribution. Can't you import it in QGIS? image If this is only happening in the docker version, I would recommend to just fix it with: pip install typing-extensions Would that be fine for you?

thielfab commented 1 year ago

Indeed, typing_extensions is not available. This will presumably be the case for Ubuntu (22.04) and all derivatives in general, not only docker (just tested with WSL and our server).

janzandr commented 1 year ago

@jakimowb, @thielfab and @danschef, please note #345.

  1. If you haven't installed typeguard, all the above problems should be gone.
  2. If you have installed typeguard yourself (not part of the EnMAP-Box requirements), I hope that everything works fine as well. Please report any issues, if not.
jakimowb commented 1 year ago

I added typeguard to requirements_developers.txt d7031f3