Skip to content

mypy crashes with overloads of functools.singledispatch #8356

Closed
@hauntsaninja

Description

@hauntsaninja

I was trying out the advice I gave in #8354, and encountered a mypy crash:

~/delete λ cat test22.py                                                                                         2 
from typing import *
import functools


@overload
def foo(val: str) -> str: ...
@overload
def foo(val: int) -> int: ...


@functools.singledispatch
def foo(x):
    return x


@foo.register
def _(x: int) -> int:
    return x + 1
~/delete λ mypy test22.py --show-traceback
test22.py:5: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.770+dev.0b9089e9c9be2ad0b345b1d3743f808365d4aefc
Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 11, in <module>
    load_entry_point('mypy', 'console_scripts', 'mypy')()
  File "/Users/shantanu/dev/mypy/mypy/__main__.py", line 8, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/Users/shantanu/dev/mypy/mypy/main.py", line 89, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 166, in build
    sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr, extra_plugins
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 234, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 2612, in dispatch
    process_graph(graph, manager)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 2919, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 3018, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 2111, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 293, in check_first_pass
    self.accept(d)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 400, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 515, in accept
    return visitor.visit_overloaded_func_def(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 433, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 460, in _visit_overloaded_func_def
    self.check_overlapping_overloads(defn)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 481, in check_overlapping_overloads
    assert isinstance(inner_type, CallableType)
AssertionError: 
test22.py:5: : note: use --pdb to drop into pdb

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions