python / python/cpython

inspect.Signature doesn't display defaults as they appear in code

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

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

stdlib
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Certain types of defaults show up in output of Signature instances as overly-verbose representations that don't match their syntax display.

>>> import inspect
>>> def a_test(a=str, b=inspect, c=inspect.Signature, d=inspect.signature, e=inspect.Signature.replace, f=(i for i in range(3))):
...    """lots of objects with awkward reprs"""
...
>>> print(inspect.signature(a_test))
(a=<class 'str'>, b=<module 'inspect' from '/Users/jeremyp/git/cpython/Lib/inspect.py'>, c=<class 'inspect.Signature'>, d=<function signature at 0x10c77e980>, e=<function Signature.replace at 0x10c77fba0>, f=<generator object <genexpr> at 0x10c6d7100>)
>>>
>>> def b_test(a: str = str):
...    """annotations seem to get this right"""
...
>>> print(inspect.signature(b_test))
(a: str = <class 'str'>)

The string representation of Signature is important as it is used, among other places, as the output of help and pydoc

>>> help(locale.atof)
Help on function atof in module locale:

atof(string, func=<class 'float'>)
    Parses a string as a float according to the locale settings.

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

Mở hướng dẫn đóng góp

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

Bắt đầu bằng cách đọc các điểm vào inspect.signature và biểu diễn chuỗi của Signature, sau đó tái hiện các ví dụ về giá trị mặc định liên quan đến lớp, mô-đun, hàm, phương thức và generator. So sánh đầu ra với cách sử dụng help và pydoc; công việc được xem là hoàn tất khi Signature hiển thị các giá trị mặc định theo cách ít quá chi tiết hơn nhưng vẫn giữ lại thông tin hữu ích cho bên gọi.

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
developer-experience
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
28/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.