TypedDict item insertion support
Đang mở
Chưa có ai nhận issue này.
feature
priority-1-normal
topic-typed-dict
- 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ả
- Are you reporting a bug, or opening a feature request?
Feature request - Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Currently I can't insert items into TypedDict even after explicit check for a defined key:
from mypy_extensions import TypedDict
GroupDataDict = TypedDict(
'GroupDataDict', {"children": str,
"vars": str,
"hosts": str}, total=False
)
test_group: GroupDataDict = {}
key = "children"
if key in ("children", "vars"):
test_group[key] = "a"
if key not in ["children", "vars"]:
raise ValueError("")
test_group[key] = "b"
print(test_group)
- What is the actual behavior/output?
-> % mypy typeddict_insertion.py
typeddict_insertion.py:12: error: TypedDict key must be a string literal; expected one of ('children', 'vars', 'hosts')
typeddict_insertion.py:16: error: TypedDict key must be a string literal; expected one of ('children', 'vars', 'hosts')
- What is the behavior/output you expect?
No error - What are the versions of mypy and Python you are using?
mypy 0.620 + Python 3.7 - Do you see the same issue after installing mypy from Git master?
I haven't tried - What are the mypy flags you are using? (For example --strict-optional)
[mypy]
python_version = 3.7
check_untyped_defs = True
disallow_any_generics = True
disallow_untyped_calls = True
ignore_errors = False
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
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 chạy ví dụ TypedDict được cung cấp với phiên bản mypy hiện tại và kiểm tra cách các biểu thức khóa TypedDict được kiểm tra. Công việc hoàn tất khi các kiểm tra tường minh giới hạn một khóa vào các tên TypedDict hợp lệ cho phép các phép gán được minh họa mà không có lỗi, trong khi các khóa không hợp lệ vẫn bị từ chối; thêm hoặc cập nhật các kiểm thử tập trung cho cả hai trường hợp.
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
- devtools
- Loại issue
- Tính năng
- Độ 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
- 42/100