dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.42k stars 59 forks source link

Crash when annotating a method with `**kwargs` #96

Open ilevkivskyi opened 4 years ago

ilevkivskyi commented 4 years ago

Trying to annotate this code:

class C:
    def test_xx(self,
                a=1,
                b=1,
                c=1,
                d=1,
                **kwargs):
        pass

triggers a crash with following traceback:

Traceback (most recent call last):
  [...snip...]
  File "/lib/python3.7/lib2to3/refactor.py", line 282, in refactor
    self.refactor_file(dir_or_file, write, doctests_only)
  File "/lib/python3.7/site-packages/pyannotate_tools/annotations/__main__.py", line 57, in refactor_file
    filename, write=write, doctests_only=doctests_only)
  File "/lib/python3.7/lib2to3/refactor.py", line 728, in refactor_file
    *args, **kwargs)
  File "/lib/python3.7/lib2to3/refactor.py", line 335, in refactor_file
    tree = self.refactor_string(input, filename)
  File "/lib/python3.7/lib2to3/refactor.py", line 367, in refactor_string
    self.refactor_tree(tree, name)
  File "/lib/python3.7/lib2to3/refactor.py", line 441, in refactor_tree
    new = fixer.transform(node, results)
  File "/lib/python3.7/site-packages/pyannotate_tools/fixes/fix_annotate.py", line 181, in transform
    self.add_py2_annot(argtypes, restype, node, results)
  File "/lib/python3.7/site-packages/pyannotate_tools/fixes/fix_annotate.py", line 276, in add_py2_annot
    self.insert_long_form(node, results, argtypes)
  File "/lib/python3.7/site-packages/pyannotate_tools/fixes/fix_annotate.py", line 342, in insert_long_form
    assert not argtypes, argtypes
AssertionError: ['**Any']

Couple notes on triggering the crash: