mypy
mypy copied to clipboard
[mypyc] singledispatch made outside the main namespace
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
- 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
- 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