Skip to content
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

INTERNAL ERROR when enabling mypy-zope for Twisted Klein #37

Closed
wsanchez opened this issue Mar 11, 2021 · 6 comments · Fixed by #38
Closed

INTERNAL ERROR when enabling mypy-zope for Twisted Klein #37

wsanchez opened this issue Mar 11, 2021 · 6 comments · Fixed by #38

Comments

@wsanchez
Copy link

In commit twisted/klein@04a536c, I enabled mypy-zope for Twisted Klein and I'm getting an INTERNAL ERROR in the build.

Here is the error with --show-traceback added:

wsanchez$ tox -e mypy -- --show-traceback src
GLOB sdist-make: /Users/wsanchez/Dropbox/Developer/Twisted/klein/setup.py
mypy inst-nodeps: /Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/.tmp/package/1/klein-20.6.0.zip
mypy installed: attrs==20.3.0,Automat==20.2.0,characteristic==14.3.0,constantly==15.1.0,hyperlink==21.0.0,idna==3.1,incremental==17.5.0,klein @ file:///Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/.tmp/package/1/klein-20.6.0.zip,mypy==0.812,mypy-extensions==0.4.3,mypy-zope==0.2.11,PyHamcrest==2.0.2,six==1.15.0,Tubes==0.2.0,Twisted==20.3.0,typed-ast==1.4.2,typing-extensions==3.7.4.3,Werkzeug==1.0.1,zope.event==4.5.0,zope.interface==5.2.0,zope.schema==6.1.0
mypy run-test-pre: PYTHONHASHSEED='3790822665'
mypy run-test: commands[0] | mypy --cache-dir=/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy_cache --pretty --show-traceback src
src/klein/test/test_trial.py:33: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.812
Traceback (most recent call last):
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/main.py", line 90, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/build.py", line 179, in build
    result = _build(
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/build.py", line 253, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/build.py", line 2638, in dispatch
    process_graph(graph, manager)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/build.py", line 2962, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/build.py", line 3060, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/build.py", line 2130, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checker.py", line 294, in check_first_pass
    self.accept(d)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/nodes.py", line 950, in accept
    return visitor.visit_class_def(self)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checker.py", line 1723, in visit_class_def
    self.accept(defn.defs)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/nodes.py", line 1015, in accept
    return visitor.visit_block(self)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checker.py", line 1972, in visit_block
    self.accept(s)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/nodes.py", line 950, in accept
    return visitor.visit_class_def(self)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checker.py", line 1749, in visit_class_def
    sig, _ = self.expr_checker.check_call(dec, [temp],
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checkexpr.py", line 930, in check_call
    result = self.check_call(call_function, args, arg_kinds, context, arg_names,
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checkexpr.py", line 911, in check_call
    return self.check_callable_call(callee, args, arg_kinds, context, arg_names,
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checkexpr.py", line 1023, in check_callable_call
    new_ret_type = self.apply_function_plugin(
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy/checkexpr.py", line 732, in apply_function_plugin
    return method_callback(
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy_zope/plugin.py", line 171, in analyze_implementation
    iface_type = self._lookup_type(ifacename, method_ctx.api)
  File "/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/lib/python3.9/site-packages/mypy_zope/plugin.py", line 583, in _lookup_type
    module = api.modules[module_name]
KeyError: 'klein.test.test_trial.TestCaseTests'
src/klein/test/test_trial.py:33: : note: use --pdb to drop into pdb
ERROR: InvocationError for command /Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy/bin/mypy --cache-dir=/Users/wsanchez/Dropbox/Developer/Twisted/klein/.tox/mypy_cache --pretty --show-traceback src (exited with code 2)
__________________________________________ summary __________________________________________
ERROR:   mypy: commands failed
@wsanchez
Copy link
Author

wsanchez commented Mar 11, 2021

It appears that the cause of the problem here is that we have this nested class that defines the interface. The INTERNAL ERROR message goes away if I move the interface definition up to the module scope.

@kedder
Copy link
Member

kedder commented Mar 11, 2021

As I understand, it fails on this file: https://github.com/twisted/klein/blob/master/src/klein/test/test_trial.py.

Can you try moving IFrobbable, Frobbable and NotFrobbable out of TestCaseTests to the top level of test_trial module?

@kedder
Copy link
Member

kedder commented Mar 11, 2021

I see, this makes sense. I'm not exactly sure how to support this case, but I'll try to at least avoid this catastrophic failure.

@wsanchez
Copy link
Author

Thanks. I don't know if it's hard to detect this case, but an error suggestion that perhaps you defined an interface in a non-module scope might help others from having to chase this down.

@kedder
Copy link
Member

kedder commented Mar 13, 2021

@wsanchez, released 0.2.12 with the fix.

@wsanchez
Copy link
Author

Verified fixed, thanks!

wsanchez added a commit to twisted/klein that referenced this issue Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants