Open twoertwein opened 2 years ago
Further, it would be great if stubtest defines error codes/categories to ignore only those categories for a function/argument
Yup:
https://github.com/python/mypy/blob/0a720edb1489af6da63f0731cbc66263598a5a5d/mypy/stubtest.py#L108
@twoertwein While stubtest should do something like this, it might be a little finnicky to get right. I assume your use case for this is to ignore errors from deprecate_nonkeyword_arguments
? In which case I have a proposal for you: make deprecate_nonkeyword_arguments
alter the function signature.
The following patch should work and passes all the tests in pandas/tests/util/test_deprecate_nonkeyword_arguments.py
. If deprecate_nonkeyword_arguments
is in fact most of your desire for this, and the patch looks plausible to you, let me know and I'll open a PR. Should hopefully be easier than allowlisting with error codes.
I assume your use case for this is to ignore errors from
deprecate_nonkeyword_arguments
? In which case I have a proposal for you: makedeprecate_nonkeyword_arguments
alter the function signature.
Wow, that would cover many cases! Are there other tools except for stubtest that benefit from exposing the "correct"/intended function signature?
I'm sure there are several, but the only one I'm aware of that I use regularly of is the ??
shortcut in IPython to show function signatures. Sounds like I should make a PR :-)
Are there other tools except for stubtest that benefit from exposing the "correct"/intended function signature?
It will also affect the signature displayed by help()
in the builtin Python REPL, as well as the IPython REPL :)
A not thought-through idea: Would it make sense for stubtest to operate in two steps: 1) Generate pyi files based on runtime inspection and 2) then "somehow" re-use mypy/pyright to compare those new pyi files with existing pyi files.
A probably very ugly way to define "somehow": For each class/function present in both pyi files, create a new python files with:
from manual_stubs import Class as Class_manual
from stubtest_stubs import Class as Class_stubtest
class Class(Class_manual, Class_stubtest): ...
from manual_stubs import fun as fun_manual
from stubtest_stubs import fun as fun_stubtest
def fun_a(fun: <signature from fun_manual>): ...
def fun_b(fun: <signature from fun_stubtest>): ...
fun_a(fun_stubtest)
fun_b(fun_manual)
then run mypy (or any other type checkers) on this file.
Feature
A function such as
pandas.read_csv
has many arguments - there are many ways in which a stub file can be incompatible with the implementation :) As far as I know, stubtest's allowlist can either ignore the entire function/method but not individual arguments or individual error codes.Pitch The allowlist could support which argument names should be ignored. Further, it would be great if stubtest defines error codes/categories to ignore only those categories for a function/argument