Closed ZanSara closed 1 year ago
Alright so the real culprit, very unfortunately, seems to be __hash__
. Or better, this is a typing
optimization, because behind the scenes it uses functools.lru_cache
to try caching types, but according to the docstring of lru_cache
:
Arguments to the cached function must be hashable.
which FakeModule
is not.
By making it hashable, typing with Optional and Union without issues. However, some tests fail:
FAILED generalimport/test/test_usage/test_cast.py::Test::test_hash - AssertionError: MissingOptionalDependency not raised
FAILED generalimport/test/test_usage/test_cast.py::Test::test_iter - AssertionError: MissingOptionalDependency not raised
FAILED generalimport/test/test_usage/test_compare.py::Test::test_eq - AssertionError: MissingOptionalDependency not raised
Do we want to trade these usecases for the possibility of typing?
Good stuff! I built an experiment on top of this in #39 - possibly giving us best of both worlds
Fixes https://github.com/ManderaGeneral/generalimport/issues/30
After adding the unit tests, seems like
__args__
is not sufficient in the general case. I'll keep investigating.