fix: @_helpers.positional raises TypeError when decorating functions without default arguments
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Issue nêu googleapiclient/_helpers.py và có ví dụ tái hiện sử dụng @_helpers.positional. Hãy đọc phần suy luận đối số của positional() được trình bày trong issue, sau đó chạy các bài kiểm thử hiện có liên quan đến helper đó. Hoàn thành khi việc trang trí một hàm không có đối số mặc định hoặc không có tham số không còn gây ra TypeError, và các bài kiểm thử hiện có của helper đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
When @googleapiclient._helpers.positional is used as a bare decorator without arguments (e.g., @positional) on a callable that does not define default argument values (or takes no parameters), it raises TypeError: object of type 'NoneType' has no len() at function definition time.
Current Behavior
In googleapiclient/_helpers.py, positional() infers the maximum number of positional arguments when called without arguments:
if isinstance(max_positional_args, int):
return positional_decorator
else:
args, _, _, defaults, _, _, _ = inspect.getfullargspec(max_positional_args)
return positional(len(args) - len(defaults))(max_positional_args)
When max_positional_args has no default parameters (or takes 0 parameters), inspect.getfullargspec(max_positional_args).defaults returns None.
Evaluating len(defaults) then raises:
TypeError: object of type 'NoneType' has no len()
Expected Behavior
When @positional is used without arguments on a function without default parameters (such as def func(a, b): ...), defaults should default to an empty sequence (e.g., len(defaults or ())), correctly calculating len(args) - 0 = len(args) positional parameters instead of crashing with a TypeError.
Reproduction
from googleapiclient import _helpers
@_helpers.positional
def my_function(a, b):
return a + b
Result:
TypeError: object of type 'NoneType' has no len()
Technical Context
In googleapiclient/_helpers.py, replacing len(defaults) with len(defaults or ()) safely treats None as 0 default arguments:
args, _, _, defaults, _, _, _ = inspect.getfullargspec(max_positional_args)
return positional(len(args) - len(defaults or ()))(max_positional_args)
- Ngôn ngữ chính
- Python
- Star
- 9k
- Fork
- 2.6k
- Merge trung bình
- 8 giờ 36 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc 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 googleapis/google-api-python-client
-
fix: @_helpers.positional raises TypeError when decorating functions without default argumentsĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
googleapis/google-api-python-client#2844 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Disable prettyPrint by default for Google Sheets API responsesCó thể đã có người làm @pawciobiel đã nhận 69 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
googleapis/google-api-python-client#2788 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
test: connection leak test test_discovery_http_is_closed is shadowed and syntactically invalidCó thể đã có người làm @Capstan đã nhận 145 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
googleapis/google-api-python-client#2757 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
test: strict positional parameter enforcement is ignored under pytestCó thể đã có người làm @Capstan đã nhận 145 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
googleapis/google-api-python-client#2755 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
googleapis/google-api-python-client#2825 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của googleapis/google-api-python-client
Issue tương tự
-
good first issue priority: low size: XS testing
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
cubrid-lab/cubrid-mcp-server#385 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue priority: low size: S testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
cubrid-lab/cubrid-cookbook-python#447 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Python PointcloudĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ArduCAM/Arducam_tof_camera#125 ·
-
area:curator enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
CassioDalla/Scrinalia#150 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Tutorial notebook: Find the leakĐang mởdocumentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100