Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

fix: @_helpers.positional raises TypeError when decorating functions without default arguments

オープン 初心者向け
#2,845 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@codeXsidd がすでに取り組んでいます。

2026年10月22日 から。

  • #2846 @codeXsidd による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

issue では googleapiclient/_helpers.py が示され、@_helpers.positional を使った再現例が含まれています。issue に示された positional() の引数推論を読み、その後、この helper に関連する既存のテストを実行してください。デフォルト引数がない関数、またはパラメータがない関数をデコレートしても TypeError が発生せず、既存の helper のテストがパスすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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)
主要言語
Python
スター
9k
フォーク
2.6k
平均マージ
8時間 36分
マージ済み PR(30日)
7

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

googleapis/google-api-python-client のほかの issue

googleapis/google-api-python-client の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。