-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
Description
In this example, the boto package has a stub, but the boto.foo module does not:
$ python3 -m mypy --py2 --silent-imports -c 'import boto.foo'
# no error
$ python3 -m mypy --py2 --silent-imports -c 'from boto import foo'
<string>:1: error: Module has no attribute 'foo'
$ python3 -m mypy --py2 --silent-imports -c 'import boto.foo; boto.foo'
<string>:1: error: "module" has no attribute "foo"
# in real code, this error is on line where boto.foo is usedAs you can see, the behavior here is inconsistent. import boto.foo gives no error, but attempting to use boto.foo later in the program does give an error.
I think the correct behavior here is for import x.y with --silent-imports to be an error when x has a stub but y does not, because this feels conceptually similar to other cases of incomplete stubs. Otherwise, you'd be in danger of importing nonexistent submodules from packages you have full stubs for, with no way to lock that down. The only downside to this approach is it means you have to use a type ignore when the stubs are incomplete, but that's already the case most of the time.