Unknown `DefaultNamedArg` raises type incompatibility errors
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ả
🐛 Bug Report
DefaultNamedArg may cause signature compatibility errors. Observed when a function has a default keyword argument in signature and is passed to be used as a function without that particular keyword argument.
To Reproduce
from typing import List, AnyStr
from glob import glob
import itertools as it
def expand_patterns(
pats: List[AnyStr],
sort=True
):
paths = it.chain(map(glob, pats))
# Argument 1 to "map" has incompatible type "Callable[[AnyStr, DefaultNamedArg(bool, 'recursive')], List[AnyStr]]"; expected "Callable[[AnyStr], List[AnyStr]]"
if sort:
paths = sorted(paths)
return paths
Expected Behavior
Not sure if this ought to happen, but I'd expect a function like foo(x: int, y='y') to be peacefully passable to a function expecting Callable[[int], Any].
Actual Behavior
# Argument 1 to "map" has incompatible type "Callable[[AnyStr, DefaultNamedArg(bool, 'recursive')], List[AnyStr]]"; expected "Callable[[AnyStr], List[AnyStr]]"
Your Environment
- Mypy version used: 0.782
- Mypy command-line flags: Default of VSCode
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.7.7
- Operating system and version: Windows 10, 2004
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
Bắt đầu bằng cách tái hiện ví dụ Python được cung cấp, có sử dụng glob, map, khả năng tương thích của Callable và DefaultNamedArg. Theo dõi cách mypy so sánh các chữ ký Callable, sau đó xác minh rằng một đối số từ khóa mặc định được xử lý theo quy tắc tương thích dự kiến và rằng lỗi không tương thích được báo cáo đã được giải quyết.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 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
- 35/100