Closed philbudne closed 8 months ago
Ah, I understand now.... Good catch!! I noted the "Any" issue in February as https://github.com/mediacloud/story-indexer/issues/233 which we put off as "long-term"
It looks like there are 29 uses of Story sub-object "getter" methods in "with" statments (plus a comment in indexer/workers/fetcher/rss-queuer.py that notes the problem!):
# mypy reval_type(rss) in "with s.rss_entry() as rss" gives Any!!
And the explicit hint, does seem to solve the problem:
(venv) ***@***.***:~/story-indexer$ cat a.py
from indexer.story import BaseStory, RSSEntry
def foo(s: BaseStory) -> None:
reveal_type(s.rss_entry())
with s.rss_entry() as r:
reveal_type(r)
r2: RSSEntry
with s.rss_entry() as r2:
reveal_type(r2)
r3 = s.rss_entry()
reveal_type(r3)
with r3:
reveal_type(r3)
(venv) ***@***.***:~/story-indexer$ mypy a.py
...
a.py:4: note: Revealed type is "indexer.story.RSSEntry"
a.py:6: note: Revealed type is "Any"
a.py:10: note: Revealed type is "indexer.story.RSSEntry"
a.py:13: note: Revealed type is "indexer.story.RSSEntry"
a.py:15: note: Revealed type is "indexer.story.RSSEntry"
I'd like to understand the failure before applying a work-around, and I'd prefer the assignment (since it avoids needing to explicitly type the variable), plus a comment like "mypy gets with ..... wrong" to a variable declaration that looks extraneous.
The problem is easy to reproduce, with a simple class with mypy (but pytype gets it right) so I've asked about it on a python/typing chat.