Repository: python/mypy

Issue:
stubgen fails with "TypeError: tuple object expected" running against `cattr` package
* Are you reporting a bug, or opening a feature request?

Bug 

* Please insert below the code you are checking with mypy,
  or a mock-up repro if the source is private. We would appreciate
  if you try to simplify your case to a minimal repro.

No code, but I'm trying to generate stubs for `cattrs`, which lives here: https://github.com/Tinche/cattrs

The command I'm using, on MyPy 0.700, is `stubgen -p cattr`. MyPy does manage to find the package. (for instance, `stubgen -p cattrs` gives the expected message `Failed to import cattrs; skipping it`)

I am running this inside a clean virtualenv.

* What is the actual behavior/output?
```
Traceback (most recent call last):
  File "/Users/peter/.local/share/virtualenvs/testpy-XO9km9Nb/bin/stubgen", line 10, in <module>
    sys.exit(main())
  File "mypy/stubgen.py", line 1191, in main
  File "mypy/stubgen.py", line 1075, in generate_stubs
  File "mypy/stubgen.py", line 899, in collect_build_targets
  File "mypy/stubgen.py", line 930, in find_module_paths_using_imports
TypeError: tuple object expected
```

* What is the behavior/output you expect?

I would expect the `out` directory to be created with some stubs.

* What are the versions of mypy and Python you are using?

Python 3.7.2, MyPy 0.700

* Do you see the same issue after installing mypy from Git master?
I get an entirely different error! Fascinating.  

```
Failed to import cattr.vendor.python2.typing; skipping it
Failed to import cattr.vendor.python3.typing; skipping it
Failed to import cattr.vendor.typing; skipping it
Critical error during semantic analysis: /Users/peter/.local/share/virtualenvs/testpy-XO9km9Nb/lib/python3.7/site-packages/cattr/converters.py:149: error: misplaced type annotation
```

I already expected that the error might lie within cattrs itself, but obviously the 0.700 error message was not helping me at all. This is a lot more useful. I suggest that this issue be closed once 0.710 is released and still manifests this improved error behavior, and then this issue may help others who are running into similar issues on older versions of MyPy.



Discussion:
This looks like a `mypyc` issue. You likely don't see the error on master because you use the interpreted version. There were no changes to `stubgen` between 0.700 and now.

Most likely @msullivan knows the answer.
Yeah it is an interaction with mypyc. Error message is bad too, so I filed https://github.com/mypyc/mypyc/issues/552.

I'll put up a PR right now. This is a very bad regression but also it is only stubgen so I dunno if it is worth a point release

Resolving patch:
diff --git a/mypy/stubutil.py b/mypy/stubutil.py
--- a/mypy/stubutil.py
+++ b/mypy/stubutil.py
@@ -129,7 +129,10 @@ def find_module_path_and_all_py3(module: str) -> Optional[Tuple[str, Optional[Li
         raise CantImport(module)
     if is_c_module(mod):
         return None
-    return mod.__file__, getattr(mod, '__all__', None)
+    module_all = getattr(mod, '__all__', None)
+    if module_all is not None:
+        module_all = list(module_all)
+    return mod.__file__, module_all
 
 
 @contextmanager


Test patch: