[mypyc] singledispatch made outside the main namespace
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
https://github.com/python/mypy/issues/13613#tasklist-block-c661a68b-595f-4b41-98a7-bf6bcaf6e3d9
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện lỗi với ví dụ singledispatch lồng nhau được cung cấp và mypyc. Bắt đầu tại visit_decorator trong mypyc/irbuild/visitor.py, sau đó theo dõi transform_decorator, gen_func_item và gen_func_ir trong mypyc/irbuild/function.py. Hoàn thành khi mypyc biên dịch ví dụ mà không gặp KeyError được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100