Skip to content

'NoneType' object has no attribute 'type' #1395

@gregwebs

Description

@gregwebs

If I give mypy just the argument for the file in question (pipeline/main.py) it works. However, when I run it on all project files, it crashes on that file. Given that there is a complex interaction going on I don't want to spend hours coming up with a minimally reproducing example and am only giving the stack trace.

The line it fails on is the last line in a function that returns None and the line calls a function imported from another module.

Traceback (most recent call last):
  File "/env/bin/mypy", line 6, in <module>
    main(__file__)
  File "/env/lib/python3.5/site-packages/mypy/main.py", line 54, in main
    type_check_only(sources, bin_dir, options)
  File "/env/lib/python3.5/site-packages/mypy/main.py", line 98, in type_check_only
    python_path=options.python_path)
  File "/env/lib/python3.5/site-packages/mypy/build.py", line 206, in build
    result = manager.process(initial_states)
  File "/env/lib/python3.5/site-packages/mypy/build.py", line 403, in process
    next.process()
  File "/env/lib/python3.5/site-packages/mypy/build.py", line 907, in process
    self.type_checker().visit_file(self.tree, self.tree.path)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 406, in visit_file
    self.accept(d)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 447, in accept
    typ = node.accept(self)
  File "/env/lib/python3.5/site-packages/mypy/nodes.py", line 413, in accept
    return visitor.visit_decorator(self)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 1888, in visit_decorator
    e.func.accept(self)
  File "/env/lib/python3.5/site-packages/mypy/nodes.py", line 382, in accept
    return visitor.visit_func_def(self)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 562, in visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 620, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 717, in check_func_def
    self.accept_in_frame(item.body)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 462, in accept_in_frame
    answer = self.accept(node, type_context)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 447, in accept
    typ = node.accept(self)
  File "/env/lib/python3.5/site-packages/mypy/nodes.py", line 526, in accept
    return visitor.visit_block(self)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 1112, in visit_block
    self.accept(s)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 447, in accept
    typ = node.accept(self)
  File "/env/lib/python3.5/site-packages/mypy/nodes.py", line 540, in accept
    return visitor.visit_expression_stmt(self)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 1534, in visit_expression_stmt
    self.accept(s.expr)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 447, in accept
    typ = node.accept(self)
  File "/env/lib/python3.5/site-packages/mypy/nodes.py", line 965, in accept
    return visitor.visit_call_expr(self)
  File "/env/lib/python3.5/site-packages/mypy/checker.py", line 1946, in visit_call_expr
    return self.expr_checker.visit_call_expr(e)
  File "/env/lib/python3.5/site-packages/mypy/checkexpr.py", line 142, in visit_call_expr
    return self.check_call_expr_with_callee_type(callee_type, e)
  File "/env/lib/python3.5/site-packages/mypy/checkexpr.py", line 193, in check_call_expr_with_callee_type
    e.arg_names, callable_node=e.callee)[0]
  File "/env/lib/python3.5/site-packages/mypy/checkexpr.py", line 218, in check_call
    if callee.is_type_obj() and callee.type_object().is_abstract:
  File "/env/lib/python3.5/site-packages/mypy/types.py", line 336, in is_type_obj
    return self.fallback.type.fullname() == 'builtins.type'
AttributeError: 'NoneType' object has no attribute 'type'

*** INTERNAL ERROR ***

pipeline/main.py:321: error: Internal error -- please report a bug at https://github.com/JukkaL/mypy/issues

NOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.
✗ ./bin/mypy --pdb pipeline/*.py
> /env/lib/python3.5/site-packages/mypy/types.py(336)is_type_obj()
-> return self.fallback.type.fullname() == 'builtins.type'
(Pdb) self.fallback
(Pdb) self.fallback.type
*** AttributeError: 'NoneType' object has no attribute 'type'

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