python / python/typing

TypeDict "dict style" positional arguments

Đang mở
#1,204 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

topic: documentation
Ngôn ngữ chính
Python
Star
1.8k
Fork
302
Merge trung bình
23 giờ
Pull request đã merge (30 ngày)
8

Mô tả

Hi.
I'm just curious why passing arguments to TypeDict is strictly constrained. I tried some variants including positional arguments style and failed. It's not reflected in docs or function signature (ctrl + p in Pycharm)
https://docs.python.org/3/library/typing.html#typing.TypedDict

In [1]: from typing import TypedDict                                                                                                                                                                       

In [2]:  
   ...: ProfileText = TypedDict(name='ProfileText', fields={'name': str, 'non variable key': str}, total=False)  # Error                                                                                   
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-7d3b7c9254f3> in <module>
----> 1 ProfileText = TypedDict(name='ProfileText', fields={'name': str, 'non variable key': str}, total=False)  # Error

TypeError: _typeddict_new() missing 1 required positional argument: 'typename'

In [3]:  
   ...: ProfileText = TypedDict('ProfileText', {'name': str, 'non variable key': str}, total=False)  # Error                                                                                               

In [4]:  
   ...: ProfileText = TypedDict('ProfileText', {'name': str, 'non variable key': str}, False)  # Error                                                                                                     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-b3b55e028c98> in <module>
----> 1 ProfileText = TypedDict('ProfileText', {'name': str, 'non variable key': str}, False)  # Error

TypeError: _typeddict_new() takes from 2 to 3 positional arguments but 4 were given

In [5]:  

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Issue đề cập đến entry point TypedDict và tài liệu Python typing; trước tiên hãy so sánh các dạng gọi bằng từ khóa và dạng gọi theo vị trí được minh họa với tài liệu đó. Xác định quy ước gọi nào cần được hỗ trợ, sau đó định nghĩa việc hoàn tất là hành vi, thông tin chữ ký, tài liệu và các bài kiểm thử nhất quán với dạng được chấp nhận.

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ó
5/5
Thời gian dự kiến
Hơn một tuần
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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.