You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: I have included a patch to the code that fixes this bug, but as I am not familiar with pull requests and tests, I would like some reader to apply this patch. Thanks.
Traceback (most recent call last):
File "D:\Solutions\trunk\Python\Pytype\pytype\tools\merge_pyi\main.py", line 101, in <module>
main()
File "D:\Solutions\trunk\Python\Pytype\pytype\tools\merge_pyi\main.py", line 82, in main
annotated_src = merge_pyi.annotate_string(args, py_src, pyi_src)
File "D:\Solutions\trunk\Python\Pytype\pytype\tools\merge_pyi\merge_pyi.py", line 928, in annotate_string
tree = tool.refactor_string(py_src + '\n', '<inline>')
File "D:\Python37\lib\lib2to3\refactor.py", line 367, in refactor_string
self.refactor_tree(tree, name)
File "D:\Python37\lib\lib2to3\refactor.py", line 441, in refactor_tree
new = fixer.transform(node, results)
File "D:\Solutions\trunk\Python\Pytype\pytype\tools\merge_pyi\merge_pyi.py", line 518, in transform
src_sig = FuncSignature(node, results)
File "D:\Solutions\trunk\Python\Pytype\pytype\tools\merge_pyi\merge_pyi.py", line 306, in __init__
self._arg_sigs = tuple(map(ArgSignature, args))
File "D:\Solutions\trunk\Python\Pytype\pytype\tools\merge_pyi\merge_pyi.py", line 123, in __init__
sig = ArgSignature._split_arg(arg_nodes)
File "D:\Solutions\trunk\Python\Pytype\pytype\tools\merge_pyi\merge_pyi.py", line 240, in _split_arg
raise KnownError() # expected/parse_error.py
pytype.tools.merge_pyi.merge_pyi.KnownError
The bug _split_arg is not prepared for a Texan input (i.e. lone star :) ). It receives an arg list with only the "*" leaf.
After stripping off this leaf, the arg list is now empty.
Proposed fix
In this case, make a return with the '*' as stars, and an empty arg. Further processing is not harmed by this.
Here is the change I made to _split_arg lines 239-240:
if len(arg) != 1:
if not arg and stars == '*': # added
return is_tuple, stars, arg_type, arg, default # added
raise KnownError() # expected/parse_error.py
Here is the resulting output, using unannotated function def in the .pyi file:
Note: I have included a patch to the code that fixes this bug, but as I am not familiar with pull requests and tests, I would like some reader to apply this patch. Thanks.
The source of the function def is
The exception traceback:
The bug
_split_arg
is not prepared for a Texan input (i.e. lone star :) ). It receives an arg list with only the"*"
leaf.After stripping off this leaf, the arg list is now empty.
Proposed fix
In this case, make a return with the '*' as
stars
, and an emptyarg
. Further processing is not harmed by this.Here is the change I made to
_split_arg
lines 239-240:Here is the resulting output, using unannotated function def in the .pyi file:
FYI: Here is a pretty-print I made of the parse tree used in this example:
The text was updated successfully, but these errors were encountered: