forked from quantumlib/Cirq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better error messaging when deprecated module can't be imported (quan…
…tumlib#4324) Adds better error messaging when deprecated module can't be imported. Now, `import cirq` prints zero warnings, even if there are errors importing the modules. Instead, when the deprecated modules are used, an informative error is thrown, including the root cause error: When `cirq_pasqal` can't be imported, `import cirq.pasqal` results in: ``` Traceback (most recent call last): File "/Users/balintp/dev/proj/Cirq/cirq-core/cirq/_compat.py", line 590, in deprecated_submodule new_module = importlib.import_module(new_module_name) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'cirq_pasqal' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<string>", line 1, in <module> File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 914, in _find_spec File "/Users/balintp/dev/proj/Cirq/cirq-core/cirq/_compat.py", line 504, in find_spec raise self.broken_module_exception cirq._compat.DeprecatedModuleImportError: cirq_pasqal cannot be imported. The typical reasons are that 1.) cirq_pasqal is not installed, or 2.) when developing Cirq, you don't have your PYTHONPATH setup. In this case run `source dev_tools/pypath`. You can check the detailed exception above for more details or run `import cirq_pasqal to reproduce the issue. ``` Note that `from cirq import pasqal` will still run and return a dummy module that will throw the same error when trying to access any of its attributes. Fixes quantumlib#4106. Fixes quantumlib#4291.
- Loading branch information
Showing
5 changed files
with
135 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters