Repository: python/mypy

Issue:
stubtest fails assertion on @typing.overload
**Bug Report**

When I run `stubtest` against `PyQt5`, or a minimal example package `Tst`, I get an `AssertionError`.  See a full shell transcript from the commands below at the end of this issue report.

```
git rev-parse HEAD
git status
python3.8 -m venv venv
venv/bin/python --version --version
venv/bin/pip install --upgrade pip setuptools wheel
venv/bin/pip install .
venv/bin/pip freeze
mkdir venv/lib/python3.8/site-packages/Tst
cat > venv/lib/python3.8/site-packages/Tst/__init__.py << EOF
import typing


def go(x: typing.Union[int, str]) -> typing.Union[int, str]:
    return x
EOF
mkdir venv/lib/python3.8/site-packages/Tst-stubs
cat > venv/lib/python3.8/site-packages/Tst-stubs/__init__.pyi << EOF
import typing


@typing.overload
def go(x: int) -> int: ...
@typing.overload
def go(x: str) -> str: ...
EOF
venv/bin/stubtest Tst
```

I expect no assertion errors.  I think the example stubs in `Tst` would actually be valid (maybe...).  I actually get an assertion error.

```bash
altendky@p1:~/repos/mypy$ venv/bin/stubtest Tst
Traceback (most recent call last):
  File "venv/bin/stubtest", line 8, in <module>
    sys.exit(main())
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 1165, in main
    return test_stubs(parse_options(sys.argv[1:]))
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 1058, in test_stubs
    for error in test_module(module):
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 180, in test_module
    yield from verify(stub, runtime, [module_name])
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 222, in verify_mypyfile
    yield from verify(
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 722, in verify_overloadedfuncdef
    stub_sig = Signature.from_overloadedfuncdef(stub)
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 469, in from_overloadedfuncdef
    assert func is not None
AssertionError
```

**Your Environment**

- Mypy version used: 89695cd476a06108051637c85455a57042d0f988 (latest `master` as of September 29, 2020 etc-details-about-TZ-etc)
- Mypy command-line flags: `stubtest Tst`
- Mypy configuration options from `mypy.ini` (and other config files): no `mypy.ini` file present
- Python version used: 3.8.5
- Operating system and version: Ubuntu 20.04.1 LTS

<details> <summary>Full shell transcript</summary>

```bash
altendky@p1:~/repos/mypy$ git rev-parse HEAD
89695cd476a06108051637c85455a57042d0f988
```
```bash
altendky@p1:~/repos/mypy$ git status
On branch master
Your branch is ahead of 'origin/master' by 11 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
```
```bash
altendky@p1:~/repos/mypy$ python3.8 -m venv venv
```
```bash
altendky@p1:~/repos/mypy$ venv/bin/python --version --version
Python 3.8.5 (default, Jul 29 2020, 21:06:26) 
[GCC 9.3.0]
```
```bash
altendky@p1:~/repos/mypy$ venv/bin/pip install --upgrade pip setuptools wheel
Collecting pip
  Using cached pip-20.2.3-py2.py3-none-any.whl (1.5 MB)
Collecting setuptools
  Using cached setuptools-50.3.0-py3-none-any.whl (785 kB)
Collecting wheel
  Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: pip, setuptools, wheel
  Attempting uninstall: pip
    Found existing installation: pip 20.1.1
    Uninstalling pip-20.1.1:
      Successfully uninstalled pip-20.1.1
  Attempting uninstall: setuptools
    Found existing installation: setuptools 47.1.0
    Uninstalling setuptools-47.1.0:
      Successfully uninstalled setuptools-47.1.0
Successfully installed pip-20.2.3 setuptools-50.3.0 wheel-0.35.1
```
```bash
altendky@p1:~/repos/mypy$ venv/bin/pip install .
Processing /home/altendky/repos/mypy
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting mypy-extensions<0.5.0,>=0.4.3
  Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Collecting typed-ast<1.5.0,>=1.4.0
  Using cached typed_ast-1.4.1-cp38-cp38-manylinux1_x86_64.whl (768 kB)
Collecting typing-extensions>=3.7.4
  Using cached typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Building wheels for collected packages: mypy
  Building wheel for mypy (PEP 517) ... done
  Created wheel for mypy: filename=mypy-0.790+dev.89695cd476a06108051637c85455a57042d0f988-py3-none-any.whl size=2453379 sha256=a21b960fa716814f2d33678fe9ee390e7a204a191edd56eba1d44e8be1a586b3
  Stored in directory: /tmp/pip-ephem-wheel-cache-5zjbvhko/wheels/44/2f/a8/acb7af991bc7b83e033c15f3c1cd55ba26ca406059a08afbae
Successfully built mypy
Installing collected packages: typing-extensions, typed-ast, mypy-extensions, mypy
Successfully installed mypy-0.790+dev.89695cd476a06108051637c85455a57042d0f988 mypy-extensions-0.4.3 typed-ast-1.4.1 typing-extensions-3.7.4.3
```
```bash
altendky@p1:~/repos/mypy$ venv/bin/pip freeze
mypy @ file:///home/altendky/repos/mypy
mypy-extensions==0.4.3
typed-ast==1.4.1
typing-extensions==3.7.4.3
```
```bash
altendky@p1:~/repos/mypy$ mkdir venv/lib/python3.8/site-packages/Tst
```
```bash
altendky@p1:~/repos/mypy$ cat > venv/lib/python3.8/site-packages/Tst/__init__.py << EOF
> import typing
> 
> 
> def go(x: typing.Union[int, str]) -> typing.Union[int, str]:
>     return x
> EOF
```
```bash
altendky@p1:~/repos/mypy$ mkdir venv/lib/python3.8/site-packages/Tst-stubs
```
```bash
altendky@p1:~/repos/mypy$ cat > venv/lib/python3.8/site-packages/Tst-stubs/__init__.pyi << EOF
> import typing
> 
> 
> @typing.overload
> def go(x: int) -> int: ...
> @typing.overload
> def go(x: str) -> str: ...
> EOF
```
```bash
altendky@p1:~/repos/mypy$ venv/bin/stubtest Tst
Traceback (most recent call last):
  File "venv/bin/stubtest", line 8, in <module>
    sys.exit(main())
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 1165, in main
    return test_stubs(parse_options(sys.argv[1:]))
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 1058, in test_stubs
    for error in test_module(module):
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 180, in test_module
    yield from verify(stub, runtime, [module_name])
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 222, in verify_mypyfile
    yield from verify(
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 722, in verify_overloadedfuncdef
    stub_sig = Signature.from_overloadedfuncdef(stub)
  File "/home/altendky/repos/mypy/venv/lib/python3.8/site-packages/mypy/stubtest.py", line 469, in from_overloadedfuncdef
    assert func is not None
AssertionError
```

</details>



Discussion:
Thanks for the great bug report (and for your patience with stubtest on gitter)! Fix incoming

Resolving patch:
diff --git a/mypy/stubtest.py b/mypy/stubtest.py
--- a/mypy/stubtest.py
+++ b/mypy/stubtest.py
@@ -784,7 +784,7 @@ def _resolve_funcitem_from_decorator(dec: nodes.OverloadPart) -> Optional[nodes.
     def apply_decorator_to_funcitem(
         decorator: nodes.Expression, func: nodes.FuncItem
     ) -> Optional[nodes.FuncItem]:
-        if not isinstance(decorator, nodes.NameExpr):
+        if not isinstance(decorator, nodes.RefExpr):
             return None
         if decorator.fullname is None:
             # Happens with namedtuple


Test patch: