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

support typeguard version 3.x #430

Open jakimowb opened 1 year ago

jakimowb commented 1 year ago

/enmapboxprocessing/reportwriter.py raises the error listed below if typguard available:

QGIS 3.30.0 Python 3.10.9 typeguard 3.0.2

  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/__init__.py", line 235, in collectEnMAPBoxAlgorithms
    from enmapboxprocessing.algorithm.algorithms import algorithms
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/__init__.py", line 38, in __wrapping_ee_import__
    _module_ = __builtin_import__(name, *args, **kwargs)
  File "/home/benni/mambaforge/envs/enmapbox_full_latest/share/qgis/python/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/algorithms.py", line 7, in <module>
    from enmapboxprocessing.algorithm.classificationperformancesimplealgorithm import \
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/__init__.py", line 38, in __wrapping_ee_import__
    _module_ = __builtin_import__(name, *args, **kwargs)
  File "/home/benni/mambaforge/envs/enmapbox_full_latest/share/qgis/python/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/classificationperformancesimplealgorithm.py", line 4, in <module>
    from enmapboxprocessing.algorithm.classificationperformancestratifiedalgorithm import \
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/__init__.py", line 38, in __wrapping_ee_import__
    _module_ = __builtin_import__(name, *args, **kwargs)
  File "/home/benni/mambaforge/envs/enmapbox_full_latest/share/qgis/python/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/classificationperformancestratifiedalgorithm.py", line 16, in <module>
    from enmapboxprocessing.reportwriter import HtmlReportWriter, CsvReportWriter, MultiReportWriter
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/__init__.py", line 38, in __wrapping_ee_import__
    _module_ = __builtin_import__(name, *args, **kwargs)
  File "/home/benni/mambaforge/envs/enmapbox_full_latest/share/qgis/python/qgis/utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/benni/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/reportwriter.py", line 151, in <module>
    class MultiReportWriter(object):
  File "/home/benni/mambaforge/envs/enmapbox_full_latest/lib/python3.10/site-packages/typeguard/_decorators.py", line 147, in typechecked
    retval = instrument(attr)
  File "/home/benni/mambaforge/envs/enmapbox_full_latest/lib/python3.10/site-packages/typeguard/_decorators.py", line 75, in instrument
    module_code = compile(module_ast, f.__code__.co_filename, "exec", dont_inherit=True)
TypeError: required field "ctx" missing from Subscript
janzandr commented 1 year ago
  1. Which typegurad version?
  2. Explain steps to reproduce the error.
janzandr commented 1 year ago

Ah, found it: image

You need to downgrade typeguard: image

jakimowb commented 1 year ago

To be compatible with other python code that requires a non-outdated typeguard versions (e.g. in other QGIS plugins), this issue needs to be solved properly. Maybee not vor EnMAP-Box 3.12, but in a near future.

jakimowb commented 5 months ago

@janzandr is there any progress in make the EnMAP-Box running with up-to-date typeguard versions? In the EnMAP-Box, typeguard is still pinned to typeguard==2.13.3, while the latest typeguard release is at 4.1.5 (already two major release differences) https://github.com/agronholm/typeguard

janzandr commented 5 months ago

Currently not working on that issue. With typeguard >2, the type checks are more rigorous. Moving to version 4 could/would introduce a lot of code breakes, which may not be covered by unittests. Making the transition to v4 could take a while. So it's more a question of priority.

jakimowb commented 4 months ago

Have you checked if there are any options to skip these "more rigorous" tests? There is a lot of documentation related to this and other config options. https://typeguard.readthedocs.io/en/latest/userguide.html#suppressing-type-checks

janzandr commented 4 months ago

Have you checked if there are any options to skip these "more rigorous" tests?

Not yet, but I can do it asap.