`__future__` annotations breaks `TypedDict` `__required/optional_keys__`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện t.py có và không có from __future__ import annotations, trên các phiên bản Python được liệt kê và với cả typing lẫn typing_extensions. Truy vết các điểm vào của TypedDict, Required và NotRequired để xác định các chú thích trì hoãn ảnh hưởng như thế nào đến việc phân loại khóa. Được xem là hoàn tất khi __required_keys__ và __optional_keys__ khớp với các chú thích đã khai báo đối với các biến thể được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
from __future__ import annotations appears to break TypedDict required/optional keys ending up in __required_keys__ and __optional_keys__. mypy works as expected though.
Using the example from https://peps.python.org/pep-0655/#usage-in-python-3-11 as the base
$ cat t.py
from __future__ import annotations
from typing_extensions import NotRequired, TypedDict
class Dog(TypedDict):
name: str
owner: NotRequired[str]
print("required", Dog.__required_keys__)
print("optional", Dog.__optional_keys__)
$ python3 t.py
required frozenset({'name', 'owner'})
optional frozenset()
With the __future__ import removed, works as expected:
$ cat t.py
from typing_extensions import NotRequired, TypedDict
class Dog(TypedDict):
name: str
owner: NotRequired[str]
print("required", Dog.__required_keys__)
print("optional", Dog.__optional_keys__)
$ python3 t.py
required frozenset({'name'})
optional frozenset({'owner'})
Note: breaks across different variations of total and Required/NotRequired and typing_extensions vs typing imports, above is just one example.
https://peps.python.org/pep-0655/#how-to-teach-this contains an example with the __future__ annotations import in place with no mention that it would not cause __required_keys__ and __optional_keys__ becoming populated as expected, so I'm assuming this is a bug.
Your environment
-
CPython versions tested on:
- 3.9.7 +
NotRequiredandTypedDictimports fromtyping_extensions - 3.10.7 + above mentioned imports from
typing_extensions - current 3.11.0rc2+ + above mentioned imports from
typing_extensions - current 3.11.0rc2+ above mentioned imports from
typing
- 3.9.7 +
-
Operating system and architecture: Linux x86_64
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 558
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.
Issue khác của python/cpython
-
docs pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
🐛 Bug 🔔 Pending processing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·