Skip to content

fix: handle functions without defaults in bare @positional - #2858

Open
guru-bharadwaj20 wants to merge 1 commit into
googleapis:mainfrom
guru-bharadwaj20:fix-positional-no-defaults
Open

guru-bharadwaj20 wants to merge 1 commit into
googleapis:mainfrom
guru-bharadwaj20:fix-positional-no-defaults

Conversation

@guru-bharadwaj20

Copy link
Copy Markdown
  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Using @positional with no argument on a function that has no default arguments raised TypeError: object of type 'NoneType' has no len(), because inspect.getfullargspec() returns None for defaults in that case. I changed it to use len(defaults or ()), as suggested in the issue, so all arguments of such a function count as positional.

I added two cases to PositionalTests.test_usage: a function with two arguments and no defaults, and a function with no arguments.

What I ran locally (Python 3.13, Windows):

  • python -m pytest tests/test__helpers.py: the new cases fail on main with the TypeError from the issue and pass with the fix (10 passed).
  • black --check (23.7.0) on the two changed files and the flake8 command from the lint nox session: clean.
  • python -m pytest tests: 324 passed. The 6 failures are in test_discovery.py and test_http.py and fail the same way on an unmodified main checkout here, so they look environment related.

No docs change needed since the docstring already describes this case.

Fixes #2844

inspect.getfullargspec() returns None for defaults when a function has no
default arguments, so len(defaults) raised TypeError when the decorator
was used without an argument. Treat a missing defaults tuple as empty.
@guru-bharadwaj20
guru-bharadwaj20 requested a review from a team as a code owner November 21, 2026 02:07
@google-cla

google-cla Bot commented Nov 21, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Nov 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the positional_wrapper helper function in googleapiclient/_helpers.py to safely handle cases where a function has no default arguments by using defaults or () instead of directly passing defaults to len(). Additionally, new unit tests have been added in tests/test__helpers.py to cover functions without defaults and functions without arguments. There are no review comments, so I have no further feedback to provide.

@guru-bharadwaj20

Copy link
Copy Markdown
Author

@googlebot I signed it!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant