Skip to content

Crash in function_type() #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gvanrossum opened this issue Nov 24, 2015 · 8 comments
Closed

Crash in function_type() #998

gvanrossum opened this issue Nov 24, 2015 · 8 comments
Labels
bug mypy got something wrong

Comments

@gvanrossum
Copy link
Member

The source has:

# Make the decorator available to all.
on_ui_thread = MainMessageQueue.on_queue

The crash log is:

Traceback (most recent call last):
  File "/Users/guido/src/mypy/scripts/mypy", line 6, in <module>
    main(__file__)
  File "/Users/guido/src/mypy/mypy/main.py", line 49, in main
    type_check_only(sources, bin_dir, options)
  File "/Users/guido/src/mypy/mypy/main.py", line 92, in type_check_only
    python_path=options.python_path)
  File "/Users/guido/src/mypy/mypy/build.py", line 197, in build
    result = manager.process(initial_states)
  File "/Users/guido/src/mypy/mypy/build.py", line 379, in process
    next.process()
  File "/Users/guido/src/mypy/mypy/build.py", line 849, in process
    self.type_checker().visit_file(self.tree, self.tree.path)
  File "/Users/guido/src/mypy/mypy/checker.py", line 371, in visit_file
    self.accept(d)
  File "/Users/guido/src/mypy/mypy/checker.py", line 379, in accept
    typ = node.accept(self)
  File "/Users/guido/src/mypy/mypy/nodes.py", line 552, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/guido/src/mypy/mypy/checker.py", line 953, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None)
  File "/Users/guido/src/mypy/mypy/checker.py", line 981, in check_assignment
    self.infer_variable_type(inferred, lvalue, self.accept(rvalue),
  File "/Users/guido/src/mypy/mypy/checker.py", line 379, in accept
    typ = node.accept(self)
  File "/Users/guido/src/mypy/mypy/nodes.py", line 929, in accept
    return visitor.visit_member_expr(self)
  File "/Users/guido/src/mypy/mypy/checker.py", line 1770, in visit_member_expr
    return self.expr_checker.visit_member_expr(e)
  File "/Users/guido/src/mypy/mypy/checkexpr.py", line 680, in visit_member_expr
    result = self.analyze_ordinary_member_access(e, False)
  File "/Users/guido/src/mypy/mypy/checkexpr.py", line 693, in analyze_ordinary_member_access
    self.named_type, self.msg)
  File "/Users/guido/src/mypy/mypy/checkmember.py", line 84, in analyze_member_access
    result = analyze_class_attribute_access(itype, name, node, is_lvalue, builtin_type, msg)
  File "/Users/guido/src/mypy/mypy/checkmember.py", line 240, in analyze_class_attribute_access
    return function_type(cast(FuncBase, node.node), builtin_type('builtins.function'))
  File "/Users/guido/src/mypy/mypy/nodes.py", line 1733, in function_type
    if func.type:
AttributeError: 'Decorator' object has no attribute 'type'

*** INTERNAL ERROR ***

ui/common/uikit.py:64: error: Internal error -- please report a bug at https://github.com/JukkaL/mypy/issues
@gvanrossum gvanrossum added the bug mypy got something wrong label Nov 24, 2015
@refi64
Copy link
Contributor

refi64 commented Nov 24, 2015

@gvanrossum If in mypy/checkmember.py, you put the following right after line 230:

print(node, t)

what is the output?

@gvanrossum
Copy link
Member Author

The last two lines of that output say:

Mdef/Decorator : def (cls: Any, html: Any) -> Any def (cls: Any, html: Any) -> Any
Mdef/Decorator : def () -> Any def () -> Any

(I have not been able to reproduce the issue in a smaller setting -- the offending line is a class method that implements the tedious pattern to support both @foo and @foo(), and the actual decorator is an invocation of something else. The code base I am trying this on is huge and I am not very familiar with it yet, so navigating it is slow.)

@refi64
Copy link
Contributor

refi64 commented Nov 24, 2015

@gvanrossum ...what if you change it to read:

print(node, t, node.node)

I think I'm getting an idea of what the issue is.

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 24, 2015

I have a repro, I think:

A.g()

class A:
    @f
    def g(self): pass


def f(x):
    return x

JukkaL added a commit that referenced this issue Nov 24, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Nov 24, 2015

I landed a workaround. Let me know if this fixes the crash.

@gvanrossum
Copy link
Member Author

Now I get a different error (on the same file):

Traceback (most recent call last):
  File "/Users/guido/src/mypy/scripts/mypy", line 6, in <module>
    main(__file__)
  File "/Users/guido/src/mypy/mypy/main.py", line 49, in main
    type_check_only(sources, bin_dir, options)
  File "/Users/guido/src/mypy/mypy/main.py", line 92, in type_check_only
    python_path=options.python_path)
  File "/Users/guido/src/mypy/mypy/build.py", line 197, in build
    result = manager.process(initial_states)
  File "/Users/guido/src/mypy/mypy/build.py", line 379, in process
    next.process()
  File "/Users/guido/src/mypy/mypy/build.py", line 849, in process
    self.type_checker().visit_file(self.tree, self.tree.path)
  File "/Users/guido/src/mypy/mypy/checker.py", line 371, in visit_file
    self.accept(d)
  File "/Users/guido/src/mypy/mypy/checker.py", line 379, in accept
    typ = node.accept(self)
  File "/Users/guido/src/mypy/mypy/nodes.py", line 473, in accept
    return visitor.visit_class_def(self)
  File "/Users/guido/src/mypy/mypy/checker.py", line 871, in visit_class_def
    self.check_multiple_inheritance(typ)
  File "/Users/guido/src/mypy/mypy/checker.py", line 889, in check_multiple_inheritance
    self.check_compatibility(name, base, base2, typ)
  File "/Users/guido/src/mypy/mypy/checker.py", line 925, in check_compatibility
    ok = is_equivalent(first_type, second_type)
  File "/Users/guido/src/mypy/mypy/subtypes.py", line 60, in is_equivalent
    return is_subtype(a, b, type_parameter_checker) and is_subtype(b, a, type_parameter_checker)
  File "/Users/guido/src/mypy/mypy/subtypes.py", line 49, in is_subtype
    return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

*** INTERNAL ERROR ***

ui/common/uikit.py:366: error: Internal error -- please report a bug at https://github.com/JukkaL/mypy/issues

JukkaL added a commit that referenced this issue Nov 25, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Nov 25, 2015

I just pushed an attempt at fixing this issue. This is probably related to #613, which is probably one of worst known issues right now.

@gvanrossum
Copy link
Member Author

Thanks, the crash is gone.

@JukkaL JukkaL closed this as completed Nov 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants