Cornerstone-OnDemand / modelkit

Toolkit for developing and maintaining ML models
http://cornerstone-ondemand.github.io/modelkit/
MIT License
155 stars 17 forks source link

NamedTuple Error with python 3.9.5 #61

Closed CyrilLeMat closed 3 years ago

CyrilLeMat commented 3 years ago

I had this error running pytest in python 3.9.5

  File "/Users/clemat/.pyenv/versions/3.9.5/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "/Users/clemat/.pyenv/versions/3.9.5/envs/modelkit/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line 170, in exec_module
    exec(co, module.__dict__)
  File "/Users/clemat/dev/modelkit/tests/assets/conftest.py", line 18, in <module>
    from modelkit.assets.manager import AssetsManager
  File "/Users/clemat/dev/modelkit/modelkit/__init__.py", line 3, in <module>
    from modelkit.core.library import ModelLibrary, load_model  # NOQA
  File "/Users/clemat/dev/modelkit/modelkit/core/__init__.py", line 1, in <module>
    from modelkit.core.library import ModelLibrary, load_model
  File "/Users/clemat/dev/modelkit/modelkit/core/library.py", line 35, in <module>
    from modelkit.core.model import Asset, AsyncModel, Model
  File "/Users/clemat/dev/modelkit/modelkit/core/model.py", line 31, in <module>
    from modelkit.utils.cache import Cache, CacheItem
  File "/Users/clemat/dev/modelkit/modelkit/utils/cache.py", line 15, in <module>
    class CacheItem(NamedTuple, Generic[ItemType]):
  File "/Users/clemat/.pyenv/versions/3.9.5/lib/python3.9/typing.py", line 1881, in _namedtuple_mro_entries
    raise TypeError("Multiple inheritance with NamedTuple is not supported")
TypeError: Multiple inheritance with NamedTuple is not supported
======================================================================================= short test summary info ========================================================================================
ERROR  - TypeError: Multiple inheritance with NamedTuple is not supported
CyrilLeMat commented 3 years ago

From what I see, this seems to be an update of NamesTuple in python 3.9 https://bugs.python.org/issue43923 https://bugs.python.org/issue40185

https://github.com/JustAnotherArchivist/snscrape/issues/111 https://github.com/Carsten-Leue/ReduxPY/issues/2

CyrilLeMat commented 3 years ago

HTe simplest seems to rewrite the CacheItem class without NamedTuple

victorbenichoux commented 3 years ago

HTe simplest seems to rewrite the CacheItem class without NamedTuple

Indeed, it looks like we should use a dataclass instead. The goal with the NamedTuple was to get really fast instantiation of these items. I will work on a PR to fix this later today.

CyrilLeMat commented 3 years ago

I just did this image

CyrilLeMat commented 3 years ago

it works but we loose the item typing

victorbenichoux commented 3 years ago

Of course, but do not want to lose typing 😄

CyrilLeMat commented 3 years ago

Here is PR to fix this issue https://github.com/clustree/modelkit/pull/62

pquentin commented 3 years ago

Closed in #62