Closed
Description
Inspired by #18699 I wrote up a very brief script that when placed in the root directory could help identify functions where **kwargs
are accepted but not used in the method body. While not perfect (may give false positives in cases of nested function definitions) it calls out 128 functions as is (see extra_kwargs.txt). A quick spot check on my end looked good.
Sharing in case anyone would like to look through this and submit PR's to tackle in batches. Here's the script I used in case anyone is interested
import re
import glob
if __name__=='__main__':
pater = re.compile(r"""
^(.+?) # group to match function name (non-greedy)
\((.*?)\) # group to match arguments
(.*)$ # everything else (function body)
""", flags=re.DOTALL|re.VERBOSE)
fns = glob.glob('pandas/**/*.py', recursive=True)
for fn in fns:
with open(fn) as infile:
source = infile.read()
funcs = source.split('def ')
for func in funcs:
res = re.search(pater, func)
if res:
nm, args, body = res.groups()
if '**kwargs' in args and not 'kwargs' in body:
args = re.sub('\s+', ' ', args)
print("{} def {}({})".format(fn, nm, " ".join(
args.split("\n"))))