You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpymongo# this can be any third-party module without stubsCollection=pymongo.collection.Collectiondeffunc(a: Collection) ->bool:
returnTrue
Here's the output of mypy test_mypy.py :
test_mypy.py:1: error: No library stub file for module 'pymongo'
test_mypy.py:1: note: (Stub files are from https://github.com/python/typeshed)
test_mypy.py: note: In function "func":
test_mypy.py:5: error: Invalid type "test_mypy.Collection"
then mypy does not complain about pymongo.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.
The text was updated successfully, but these errors were encountered:
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.
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!deffunc(a: Collection) ->bool: # OKreturnTrue
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.The text was updated successfully, but these errors were encountered: