Open frankpf opened 7 years ago
This seems similar to https://github.com/python/mypy/issues/2075.
Looks like it doesn't treat Collection = pymongo.collection.Collection
as a type alias definition? In the second example, pymongo
is an object of type Any
and attributes thereof are also treated as Any
.
Agreed this should be dealt with better.
I've hit this issue as well. It's not clear if Collection
should be treated as a type alias, since it could also be an ordinary variable. Mypy should perhaps behave as if there was an explicit Any
annotation. This doesn't generate an error:
...
Collection: Any = pymongo.collection.Collection # Note type annotation!
def func(a: Collection) -> bool: # OK
return True
test_mypy.py
:Here's the output of
mypy test_mypy.py
:However, if I change
test_mypy.py
to this:then
mypy
does not complain aboutpymongo.collection.Collection
being an invalid type. This seems inconsistent/wrong,Collection
is not an invalid type, it's just an alias for a type without a stub.