Skip to content

Crash when annotating a method with **kwargs #96

@ilevkivskyi

Description

@ilevkivskyi

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:

  • It must be a method, not function
  • The signature must be long

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions