Closed sotte closed 2 years ago
Sorry for leaving this hanging for such a long time. It got lost in my messages :disappointed:
This is a difficult one.. it's not really practical to remove the lru_cache without a big performance hit. I have been experimenting with a slightly different internal design that does it's own form of caching, I haven't done any testing with mypy.
I tried the potential fix, but I wasn't able to get it working. If you have any suggestions that would be great.
In lieu of a solution, and since this is still an open ticket on the mypy
library, it might be easiest to just remove the typing information from the get_component/s
methods for now :thinking:
Hey @benmoran56 , first of all thanks for this nice library. I'm really enjoying using it!
I noticed that the type annotations for
get_component
andget_components
are not quite correct. Let's talk aboutget_component
here, as it's easier. (get_components
has the same plus another issue. I'll create a sep. issue for that one.)get_component()
is decorated withlru_cache
, but thelru_cache
swallows the type annotations (ref https://github.com/python/mypy/issues/5107). As a result the type of the returned component cannot be inferred.I type checked it with pyright, but other type checkers should yield similar results.
Potential Fix
A solution is to add type hits at type checking time (as suggested here https://github.com/python/mypy/issues/5107):
Code to reproduce
Here is the code to reproduce the issue: