0

当我尝试在使用基于 S3 的 Python 导入器支持的 AWS Lambda 中运行绝地时,我收到 ValueError: not enough values to unpack (expected 1, got 0) 异常。我设法让 parso 和 jedi 使用两个符合 Python 标准的小型补丁,但对于这个我感到无能为力。这是堆栈跟踪、调试输出和测试功能代码。它在本地工作。任何可以查看的想法都将受到高度赞赏。最终目标是探索拥有完全无服务器 Python IDE 的可能性。

 1. Debug output and Stack trace:
dbg: Start: infer
dbg: infer_node <Name: variable@16,4>@(16, 4) in MixedModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: context.goto <Name: variable@16,4> in (MixedModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)): [<TreeNameDefinition: string_name=variable start_pos=(15, 4)>]
dbg: global search_module 'builtins': <CompiledModule: <module 'builtins' (built-in)>>
dbg: infer_node PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Name: keyword@15,17>, <Operator: ,>, <Name: f@15,26>, <Operator: ,>, <Name: C@15,29>, <Operator: ,>, <Name: x@15,32>]), <Operator: ]>])@(15, 16) in ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: iterate <SequenceLiteralValue of PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Name: keyword@15,17>, <Operator: ,>, <Name: f@15,26>, <Operator: ,>, <Name: C@15,29>, <Operator: ,>, <Name: x@15,32>]), <Operator: ]>])>
dbg: infer_node <Name: keyword@15,17>@(15, 17) in ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: context.goto <Name: keyword@15,17> in (ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)): [<TreeNameDefinition: string_name=keyword start_pos=(2, 7)>]
dbg: global search_module 'keyword': <ModuleValue: keyword@3-95 is_stub=False>
dbg: after import: S{<ModuleValue: keyword@3-95 is_stub=False>}
dbg: context.names_to_types: [<TreeNameDefinition: string_name=keyword start_pos=(2, 7)>] -> S{<ModuleValue: keyword@3-95 is_stub=False>}
dbg: infer_node <Name: f@15,26>@(15, 26) in ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: context.goto <Name: f@15,26> in (ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)): [<TreeNameDefinition: string_name=f start_pos=(12, 4)>]
dbg: context.names_to_types: [<TreeNameDefinition: string_name=f start_pos=(12, 4)>] -> S{<FunctionValue: <Function: f@12-14>>}
dbg: infer_node <Name: C@15,29>@(15, 29) in ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: context.goto <Name: C@15,29> in (ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)): [<TreeNameDefinition: string_name=C start_pos=(4, 6)>]
dbg: context.names_to_types: [<TreeNameDefinition: string_name=C start_pos=(4, 6)>] -> S{<ClassValue: <Class: C@4-6>>}
dbg: infer_node <Name: x@15,32>@(15, 32) in ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: context.goto <Name: x@15,32> in (ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)): [<TreeNameDefinition: string_name=x start_pos=(10, 0)>]
dbg: infer_expr_stmt <ExprStmt: x = D()@10,0> (<Name: x@10,0>)
dbg: infer_node PythonNode(atom_expr, [<Name: D@10,4>, PythonNode(trailer, [<Operator: (>, <Operator: )>])])@(10, 4) in ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: infer_node <Name: D@10,4>@(10, 4) in ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)
dbg: context.goto <Name: D@10,4> in (ModuleContext(<ModuleValue: __main__@2-16 is_stub=False>)): [<TreeNameDefinition: string_name=D start_pos=(7, 6)>]
dbg: context.names_to_types: [<TreeNameDefinition: string_name=D start_pos=(7, 6)>] -> S{<ClassValue: <Class: D@7-9>>}
dbg: infer_trailer: PythonNode(trailer, [<Operator: (>, <Operator: )>]) in S{<ClassValue: <Class: D@7-9>>}
dbg: execute: <ClassValue: <Class: D@7-9>> <TreeArguments: None>
dbg: context.goto 'object' in (<CompiledModule: <module 'builtins' (built-in)>>): [<CompiledName: (<CompiledValueName: string_name=builtins>).object>]
dbg: context.names_to_types: [<CompiledName: (<CompiledValueName: string_name=builtins>).object>] -> S{<CompiledValue: <class 'object'>>}
dbg: execute result: S{<TreeInstance of <ClassValue: <Class: D@7-9>>(<TreeArguments: None>)>} in <ClassValue: <Class: D@7-9>>
dbg: infer_expr_stmt result S{<TreeInstance of <ClassValue: <Class: D@7-9>>(<TreeArguments: None>)>}
dbg: context.names_to_types: [<TreeNameDefinition: string_name=x start_pos=(10, 0)>] -> S{<TreeInstance of <ClassValue: <Class: D@7-9>>(<TreeArguments: None>)>}
dbg: Dynamic array search for <SequenceLiteralValue of PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Name: keyword@15,17>, <Operator: ,>, <Name: f@15,26>, <Operator: ,>, <Name: C@15,29>, <Operator: ,>, <Name: x@15,32>]), <Operator: ]>])>
dbg: Start: Resolve lazy value wrapper
dbg: iterate <SequenceLiteralValue of PythonNode(atom, [<Operator: [>, PythonNode(testlist_comp, [<Name: keyword@15,17>, <Operator: ,>, <Name: f@15,26>, <Operator: ,>, <Name: C@15,29>, <Operator: ,>, <Name: x@15,32>]), <Operator: ]>])>
dbg: global search_module 'types': <ModuleValue: types@1-267 is_stub=False>
Module: S{<ModuleValue: types@1-267 is_stub=False>}
dbg: context.goto 'FunctionType' in (<ModuleValue: types@1-267 is_stub=False>): [<TreeNameDefinition: string_name=FunctionType start_pos=(12, 0)>]
dbg: infer_expr_stmt <ExprStmt: FunctionType = type(_f)@12,0> (<Name: FunctionType@12,0>)
dbg: infer_node PythonNode(atom_expr, [<Name: type@12,15>, PythonNode(trailer, [<Operator: (>, <Name: _f@12,20>, <Operator: )>])])@(12, 15) in ModuleContext(<ModuleValue: types@1-267 is_stub=False>)
dbg: infer_node <Name: type@12,15>@(12, 15) in ModuleContext(<ModuleValue: types@1-267 is_stub=False>)
dbg: context.goto <Name: type@12,15> in (ModuleContext(<ModuleValue: types@1-267 is_stub=False>)): [<CompiledName: (<CompiledValueName: string_name=builtins>).type>]
dbg: context.names_to_types: [<CompiledName: (<CompiledValueName: string_name=builtins>).type>] -> S{<CompiledValue: <class 'type'>>}
dbg: infer_trailer: PythonNode(trailer, [<Operator: (>, <Name: _f@12,20>, <Operator: )>]) in S{<CompiledValue: <class 'type'>>}
dbg: infer_node <Name: _f@12,20>@(12, 20) in ModuleContext(<ModuleValue: types@1-267 is_stub=False>)
dbg: context.goto <Name: _f@12,20> in (ModuleContext(<ModuleValue: types@1-267 is_stub=False>)): [<TreeNameDefinition: string_name=_f start_pos=(11, 4)>]
dbg: context.names_to_types: [<TreeNameDefinition: string_name=_f start_pos=(11, 4)>] -> S{<FunctionValue: <Function: _f@11-12>>}
dbg: builtin start <CompiledValue: <class 'type'>>
Module: S{<ModuleValue: types@1-267 is_stub=False>}
dbg: context.goto 'FunctionType' in (<ModuleValue: types@1-267 is_stub=False>): [<TreeNameDefinition: string_name=FunctionType start_pos=(12, 0)>]
warning: catched stmt recursion: <ExprStmt: FunctionType = type(_f)@12,0> @(12, 0)
dbg: context.names_to_types: [<TreeNameDefinition: string_name=FunctionType start_pos=(12, 0)>] -> S{}
Name: S{}
dbg: End: Resolve lazy value wrapper
dbg: End: infer
not enough values to unpack (expected 1, got 0): ValueError
Traceback (most recent call last):
  File "/var/task/index.py", line 17, in handle_event
    return _test_infer_type()
  File "./service/python/_test_infer_type.py", line 34, in _test_infer_type
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/api/helpers.py", line 482, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/api/__init__.py", line 311, in infer
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/api/__init__.py", line 331, in _infer
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/api/helpers.py", line 164, in infer
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/__init__.py", line 179, in infer
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/helpers.py", line 80, in infer_call_of_leaf
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/context.py", line 222, in infer_node
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 156, in infer_node
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 169, in _infer_node_if_inferred
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/cache.py", line 44, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 174, in _infer_node_cached
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/debug.py", line 82, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 82, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 184, in _infer_node
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 309, in infer_atom
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/context.py", line 75, in py__getattribute__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 414, in from_sets
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/context.py", line 75, in <genexpr>
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/names.py", line 282, in infer
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/__init__.py", line 21, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/stdlib.py", line 844, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 741, in tree_name_to_values
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 298, in iterate_values
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 414, in from_sets
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 297, in <genexpr>
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 466, in iterate
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/iterable.py", line 361, in py__iter__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/dynamic_arrays.py", line 40, in check_array_additions
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/cache.py", line 44, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/debug.py", line 82, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/dynamic_arrays.py", line 76, in _internal_check_array_additions
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/iterable.py", line 190, in name
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/compiled/value.py", line 423, in __init__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 320, in __getattr__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/utils.py", line 75, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/cache.py", line 111, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 328, in _wrapped_value
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/iterable.py", line 205, in _get_wrapped_value
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/cache.py", line 44, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/iterable.py", line 197, in _cached_generics
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/iterable.py", line 338, in _get_generics
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/iterable.py", line 193, in _get_generics
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 461, in py__class__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 398, in __init__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 461, in <genexpr>
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/function.py", line 164, in py__class__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/helpers.py", line 198, in values_from_qualified_names
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 481, in py__getattribute__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 414, in from_sets
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 481, in <genexpr>
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 81, in py__getattribute__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 414, in from_sets
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 81, in <genexpr>
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/names.py", line 282, in infer
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/__init__.py", line 21, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/stdlib.py", line 844, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 746, in tree_name_to_values
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 82, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 384, in infer_expr_stmt
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/debug.py", line 82, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 417, in _infer_expr_stmt
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/context.py", line 222, in infer_node
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 156, in infer_node
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 169, in _infer_node_if_inferred
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/cache.py", line 44, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 174, in _infer_node_cached
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/debug.py", line 82, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 82, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 208, in _infer_node
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/syntax_tree.py", line 280, in infer_trailer
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 472, in execute
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 414, in from_sets
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 472, in <genexpr>
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/__init__.py", line 21, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/stdlib.py", line 131, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/stdlib.py", line 173, in wrapper
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/plugins/stdlib.py", line 219, in builtins_type
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 461, in py__class__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 398, in __init__
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/base_value.py", line 461, in <genexpr>
  File "/tmp/tmp9_1lc7fp/lib/python/jedi/inference/value/function.py", line 164, in py__class__
ValueError: not enough values to unpack (expected 1, got 0)

 2. Test Function Code:

 from jedi import settings, Interpreter, debug

settings.cache_directory = '/tmp'
debug.debug_function = debug.print_to_stdout
debug.enable_warning = True
debug.enable_notice = True
namespaces = [locals()]

source_1 = '''
import keyword

class C:
    pass

class D:
    pass

x = D()

def f():
    pass

for variable in [keyword, f, C, x]:
    variable'''

source_2 = '''
import json
json.lo'''


def _test_infer_type():
    '''test type inference'''
    script = Interpreter(source_1, namespaces)
    defs = sorted(script.infer(), key=lambda d: d.line)
    types = [str(d.type) for d in defs]
    assert(['module', 'class', 'instance', 'function'] == types)

    return 'OK'
4

0 回答 0