fix(decorators): guard _get_fn_argnames against empty positional args (closes #2422) - #2430
Open
feiiiiii5 wants to merge 1 commit into
Open
fix(decorators): guard _get_fn_argnames against empty positional args (closes #2422)#2430feiiiiii5 wants to merge 1 commit into
feiiiiii5 wants to merge 1 commit into
Conversation
…closes unionai-oss#2422) _get_fn_argnames() accessed arg_spec_args[0] without checking if the list was empty. Functions with only keyword-only args (def f(*, x)), variadic args (def f(*args)), or keyword-variadic args (def f(**kwargs)) have an empty args list from inspect.getfullargspec, causing IndexError. Fix: add an early return when arg_spec_args is empty, before the [0] access. This is safe because there are no self/cls args to exclude. Impact: any pandera decorator (@check_input, @check_output, @check_io, @check_types) applied to a function with only keyword-only parameters would crash during argument introspection. Regression tests cover: - keyword-only args (exact repro from unionai-oss#2422) - variadic args only (*args) - kwargs only (**kwargs) - no args at all - Normal cases still work (regular function, method excludes self, mixed positional + keyword-only) Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
_get_fn_argnames()inpandera/decorators.pyaccessedarg_spec_args[0]without checking if the list was empty. Functions with only keyword-only args (def f(*, x)), variadic args (def f(*args)), or keyword-variadic args (def f(**kwargs)) have an emptyargslist frominspect.getfullargspec, causingIndexError: list index out of range.Fix
Add an early return when
arg_spec_argsis empty, before the[0]access:This is safe because there are no
self/clsargs to exclude when the positional args list is empty.Test
tests/pandas/test_get_fn_argnames_empty.py)*args)**kwargs)selfDiff scope
2 files changed, +90/-0 lines (5 lines fix + 86 lines tests)
AI Disclosure
AI-assisted debug/initial draft/testing. Root cause from issue #2422 analysis. Tests verified locally. Human review of diff scope and correctness.