fix: @_helpers.positional raises TypeError when decorating functions without default arguments
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
Research direction
The issue points to googleapiclient/_helpers.py and the positional() default inference path. Read that function and inspect its existing tests for bare decorator use; add coverage for functions with no defaults and no parameters. Done when those cases no longer raise during decoration and the tests pass.
Written by the indexing model from the issue text.
Description
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)
- Dominant language
- Python
- Stars
- 9k
- Forks
- 2.6k
- Avg merge
- 28m
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-api-python-client
-
fix: @_helpers.positional raises TypeError when decorating functions without default argumentsPossibly taken @codeXsidd claimed this 22 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Disable prettyPrint by default for Google Sheets API responsesPossibly taken @pawciobiel claimed this 91 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
test: connection leak test test_discovery_http_is_closed is shadowed and syntactically invalidPossibly taken @Capstan claimed this 167 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
googleapis/google-api-python-client#2757 · 1 comment ·
-
test: strict positional parameter enforcement is ignored under pytestPossibly taken @Capstan claimed this 167 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
eMudhra/emSign CA compromise (October 2026): what Cloud SDK Python Libraries developers need to doOpen
Difficulty 1/5 Under an hour Newbie friendliness 15/100
All issues in googleapis/google-api-python-client
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dbt-labs/spark-utils#51 ·
-
bug pydanty:is-working
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pydantic/pydantic-ai#13444 ·
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
changelog investigate
Difficulty 1/5 Under an hour Newbie friendliness 68/100
ramnes/notion-sdk-py#502 ·