Skip to content

Stubtest: option to ignore "runtime does not have argument" when implementation accepts *args/**kwargs #13305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
twoertwein opened this issue Aug 1, 2022 · 3 comments · Fixed by #13307
Labels

Comments

@twoertwein
Copy link

Feature

Pandas uses many decorators. Some of them change the function signature, e.g., @deprecate_nonkeyword_arguments(...) exposes a function that accepts *args, **kwargs instead of the original function. It would be nice to have an option to suppress "runtime does not have argument"-warnings when the implementation accepts *args/**kwargs.

Pitch

Add an option to deal with decorators or args/kwargs.

@hauntsaninja

@hauntsaninja
Copy link
Collaborator

I assume you're referring to errors like the following?

pandas.DataFrame.ffill is inconsistent, runtime argument "inplace" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime argument "limit" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime argument "downcast" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime does not have argument "downcast"
pandas.DataFrame.ffill is inconsistent, runtime does not have argument "inplace"
pandas.DataFrame.ffill is inconsistent, runtime does not have argument "limit"

stubtest does actually handle decorators and args / kwargs mostly well. The issue is that pandas.DataFrame.ffill does not look like it takes *args, **kwargs. Because deprecate_nonkeyword_arguments uses functools.wraps, inspect.signature sees a more complete signature:

In [4]: inspect.signature(pandas.DataFrame.ffill)
Out[4]: <Signature (self: 'DataFrame', axis: 'None | Axis' = None, inplace: 'bool' = False, limit: 'None | int' = None, downcast=None) -> 'DataFrame | None'>

stubtest's output^ is confusing, but it basically is reporting errors twice, once when checking whether positional args match and once when checking whether keyword-only args match:

pandas.DataFrame.ffill is inconsistent, runtime argument "downcast" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime does not have [keyword-only] argument "downcast"

If I were to fix the duplication, you'd still get the following (because inspect.signature sees the full signature because of functools.wraps):

pandas.DataFrame.ffill is inconsistent, runtime argument "inplace" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime argument "limit" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime argument "downcast" is not keyword-only

@twoertwein
Copy link
Author

Thank you, that makes sense that it errors because of the arguments not being keyword-only! I focused only on the many "runtime does not have argument" warnings which did not seem very intuitive.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Aug 2, 2022
Avoid issuing duplicate errors for keyword-only mismatches.
Fixes python#13305

Fix cases where PEP 570 is used in the stub
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 2, 2022

#13307 will fix the duplicate error, so will just say:

pandas.DataFrame.ffill is inconsistent, runtime argument "inplace" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime argument "limit" is not keyword-only
pandas.DataFrame.ffill is inconsistent, runtime argument "downcast" is not keyword-only

hauntsaninja added a commit that referenced this issue Aug 4, 2022
Avoid issuing duplicate errors for keyword-only mismatches.
Fixes #13305

Fix cases where PEP 570 is used in the stub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants