Repository navigation
fix: handle functions without defaults in bare @positional - #2858
guru-bharadwaj20 wants to merge 1 commit into
Conversation
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.
|
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. |
There was a problem hiding this comment.
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.
|
@googlebot I signed it! |
Using
@positionalwith no argument on a function that has no default arguments raisedTypeError: object of type 'NoneType' has no len(), becauseinspect.getfullargspec()returnsNonefordefaultsin that case. I changed it to uselen(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 theflake8command from thelintnox session: clean.python -m pytest tests: 324 passed. The 6 failures are intest_discovery.pyandtest_http.pyand 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