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

mypy error trying to check pymc3 #5560

Closed
rpgoldman opened this issue Sep 2, 2018 · 6 comments
Closed

mypy error trying to check pymc3 #5560

rpgoldman opened this issue Sep 2, 2018 · 6 comments

Comments

@rpgoldman
Copy link

rpgoldman commented Sep 2, 2018

  • Are you reporting a bug, or opening a feature request?
    Bug report, for the following error:
    pymc3/backends/hdf5.py:101: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.620
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
    Tried testing the code in this repo:
    origin git@github.com:rpgoldman/pymc3.git
  • What is the actual behavior/output?
    See error report above.
  • What is the behavior/output you expect?
    No runtime error.
  • What are the versions of mypy and Python you are using?
    mypy 0.620, python 3.7.0
  • Do you see the same issue after installing mypy from Git master?
    Will check and then update this ticket
  • What are the mypy flags you are using? (For example --strict-optional)
    mypy --show-traceback --ignore-missing-imports pymc3/ > /tmp/mypy-transcript.txt
  • If mypy crashed with a traceback, please paste
    the full traceback below.
pymc3/model.py:672: error: Decorated property not supported
pymc3/variational/opvi.py:1556: error: Decorated property not supported
pymc3/variational/flows.py:193: error: Decorated property not supported
pymc3/__init__.py:25: error: Name 'utils' already defined (by an import)
pymc3/data.py:226: error: Need type annotation for 'RNG'
Traceback (most recent call last):
  File "/Users/rpg/Library/Python/3.7/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/main.py", line 91, in main
    res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/main.py", line 148, in type_check_only
    fscache=fscache)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 177, in build
    flush_errors, fscache)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 350, in _build
    graph = dispatch(sources, manager)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2560, in dispatch
    process_graph(graph, manager)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2853, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2976, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2151, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 253, in check_first_pass
    self.accept(d)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 352, in accept
    stmt.accept(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 808, in accept
    return visitor.visit_class_def(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1368, in visit_class_def
    self.accept(defn.defs)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 352, in accept
    stmt.accept(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 873, in accept
    return visitor.visit_block(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1514, in visit_block
    self.accept(s)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 352, in accept
    stmt.accept(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 443, in accept
    return visitor.visit_overloaded_func_def(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 385, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 409, in _visit_overloaded_func_def
    self.check_method_override(defn)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1198, in check_method_override
    self.check_method_or_accessor_override_for_base(defn, base)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1208, in check_method_or_accessor_override_for_base
    self.check_method_override_for_base_with_name(defn, name, base)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1252, in check_method_override_for_base_with_name
    assert False, str(base_attr.node)
AssertionError: Var(sampler_vars)
@rpgoldman
Copy link
Author

Testing with mypy 0.630+dev-581e514162797b531a01b86b5266b081e955d6df, commit 8c90771a20e4dff68e416d832c66b0df5dc2f958 from master.
I see the same error. New traceback follows:

pymc3/model.py:672: error: Decorated property not supported
pymc3/variational/opvi.py:1556: error: Decorated property not supported
pymc3/variational/flows.py:193: error: Decorated property not supported
pymc3/__init__.py:25: error: Name 'utils' already defined (by an import)
pymc3/data.py:226: error: Need type annotation for 'RNG'
Traceback (most recent call last):
  File "/Users/rpg/Library/Python/3.7/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/main.py", line 91, in main
    res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/main.py", line 148, in type_check_only
    fscache=fscache)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 183, in build
    flush_errors, fscache)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 356, in _build
    graph = dispatch(sources, manager)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2519, in dispatch
    process_graph(graph, manager)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2811, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2934, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2109, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 256, in check_first_pass
    self.accept(d)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 355, in accept
    stmt.accept(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 820, in accept
    return visitor.visit_class_def(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1461, in visit_class_def
    self.accept(defn.defs)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 355, in accept
    stmt.accept(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 885, in accept
    return visitor.visit_block(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1607, in visit_block
    self.accept(s)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 355, in accept
    stmt.accept(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 455, in accept
    return visitor.visit_overloaded_func_def(self)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 388, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 412, in _visit_overloaded_func_def
    self.check_method_override(defn)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1250, in check_method_override
    self.check_method_or_accessor_override_for_base(defn, base)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1260, in check_method_or_accessor_override_for_base
    self.check_method_override_for_base_with_name(defn, name, base)
  File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1304, in check_method_override_for_base_with_name
    assert False, str(base_attr.node)
AssertionError: Var(sampler_vars)

@ilevkivskyi
Copy link
Member

Here is a simple repro for the crash:

[case testWhateverOver]
import a
[file b.py]
import a
class Sub(a.Base):
    def x(self) -> int: pass

[file a.py]
import b
class Base:
    def __init__(self):
        self.x = 1
[out]

The repro includes an import cycle, but didn't find any obvious import cycles that part of PyMC3. Maybe the same crash happens if the base node gets deferred or something. I am not sure we can get the fix in the upcoming release (the schedule is a bit too tight), but it would be good to fix this before the following release beginning of October.

@rpgoldman
Copy link
Author

I think there's an import cycle.
pymc3's backends/__init__.py imports backends.hdf5:

from ..backends.hdf5 import HDF5

and then backends/hdf5.py imports backends:

from ..backends import base, ndarray

Is this the kind of cycle you refer to?
If so, is there a way to break this cycle? Maybe by moving base and ndarray out of __init__.py into their own submodules? I'm afraid I'm sort of a novice with python, so not sure what import cycles are and aren't legit.

@rpgoldman
Copy link
Author

No, sorry -- my bad, I didn't understand the code when I wrote the above. The backends base and ndarray are not lexically contained in __init__.py, so this is not a cycle.

@ilevkivskyi
Copy link
Member

If so, is there a way to break this cycle?

An import cycle is not an error, just a sign of suboptimal design/style. This sometimes happens in larger/older frameworks (even mypy has few import cycles).

Sometimes it is hard to break import cycles (especially if you are working with large codebase), you can just wait few weeks until this issue is fixed.

@rpgoldman
Copy link
Author

Thanks for the advice. I was hoping for a work-around since the PyMC3 code base is tricky and definitely has some type errors in it. This error seems to happen before mypy gets to doing any checking, so it means that mypy doesn't work at all on the PyMC3 code.

@ilevkivskyi ilevkivskyi mentioned this issue Sep 5, 2018
12 tasks
ilevkivskyi added a commit that referenced this issue Sep 20, 2018
Fixes #5560 
Fixes #5548 

Half of the PR is updating various function signatures to also accept `Decorator`. I still prohibit `Decorator` as a target in fine-grained mode, but I think there should be no harm to defer it in normal mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants