Skip to content

Exception in partial_type.type #1747

Closed

Description

@twk

I got this error parsing a large file:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/bin/mypy", line 6, in
main(file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/main.py", line 55, in main
res = type_check_only(sources, bin_dir, options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/main.py", line 103, in type_check_only
python_path=options.python_path)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 217, in build
dispatch(sources, manager)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 1353, in dispatch
process_graph(graph, manager)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 1486, in process_graph
process_stale_scc(graph, scc)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 1516, in process_stale_scc
graph[id].type_check()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 1333, in type_check
manager.type_checker.visit_file(self.tree, self.xpath)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 430, in visit_file
self.accept(d)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 479, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 650, in accept
return visitor.visit_class_def(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 1069, in visit_class_def
self.accept(defn.defs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 479, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 713, in accept
return visitor.visit_block(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 1164, in visit_block
self.accept(s)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 479, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 534, in accept
return visitor.visit_decorator(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 1973, in visit_decorator
e.func.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 465, in accept
return visitor.visit_func_def(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 592, in visit_func_def
self.check_func_item(defn, name=defn.name())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 650, in check_func_item
self.check_func_def(defn, typ, name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 759, in check_func_def
self.accept_in_frame(item.body)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 494, in accept_in_frame
answer = self.accept(node, type_context)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 479, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 713, in accept
return visitor.visit_block(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 1164, in visit_block
self.accept(s)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 479, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 727, in accept
return visitor.visit_expression_stmt(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 1603, in visit_expression_stmt
self.accept(s.expr)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 479, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 1183, in accept
return visitor.visit_call_expr(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 2035, in visit_call_expr
return self.expr_checker.visit_call_expr(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checkexpr.py", line 136, in visit_call_expr
self.try_infer_partial_type(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checkexpr.py", line 160, in try_infer_partial_type
if partial_type.type is None:
AttributeError: 'NoneType' object has no attribute 'type'

The referenced line of code was the second one here:

results.sort(cmp=lambda x, y: cmp(x[0], y[0]))
results = [x[1] for x in results]

Activity

  1. twk commented on Jun 26, 2016

    @twk
    Author

    This is using the following args on a single file: --check-untyped-defs --silent-imports --py2

  2. added a commit that references this issue on Jun 27, 2016
    56a4990
  3. gvanrossum commented on Jun 27, 2016

    @gvanrossum
    Member

    I have a rather dumb fix that simply avoids the crash.

    I don't understand what's going on exactly[1] -- it seems we have a variable ('results') that appears as a key in the partial_types dict, but var.type is None. In fact about half of the variables in partial_types have no type. I'm guessing this is because there are errors in the vicinity -- when I fix the crash, the file gets lots of "Need type annotation for variable" errors, and there's also another error on the same line:
    Unexpected keyword argument "cmp" for "sort" of "list"

    So I suppose my simple defensive check is all right.

    [1] The author gave me a private copy of the exact code that triggered the crash.

  4. added a commit that references this issue on Jun 27, 2016
    53d6e24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions