mypy icon indicating copy to clipboard operation
mypy copied to clipboard

[mypyc] singledispatch made outside the main namespace

Open nstarman opened this issue 3 years ago • 0 comments

Mypyc cannot compile if there's a singledispatch function defined outside the main namespace, for example in the body of a function or class.

To Reproduce

  1. Make a file with the following contents
from __future__ import annotations
from functools import singledispatch, _SingleDispatchCallable
from typing import Any


def outer() -> _SingleDispatchCallable:

    @singledispatch
    def inner(obj: object) -> Any:
        return 2

    return inner
  1. Compile with mypyc

Actual Behavior

Traceback (most recent call last):
  File "mypyc/irbuild/builder.py", line 176, in accept
  File "mypy/nodes.py", line 831, in accept
  File "mypyc/irbuild/visitor.py", line 123, in visit_decorator
  File "mypyc/irbuild/function.py", line 86, in transform_decorator
  File "mypyc/irbuild/function.py", line 312, in gen_func_item
  File "mypyc/irbuild/function.py", line 351, in gen_func_ir
src/.../mwe.py:8: KeyError: <mypy.nodes.FuncDef object at 0x10a7bfb80>

The error occurs at the location of the @singledispatch.

Your Environment

  • Mypy version used: '0.950'
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: Python 3.10.4
  • Operating system and version: macOS Monterey 12.5.1

nstarman avatar Sep 05 '22 16:09 nstarman