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
better error messaging when deprecated module can't be imported #4324
better error messaging when deprecated module can't be imported #4324
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not 100% sure exactly how this works, but it looks well tested enough and is an improvement on what we have!
@@ -457,6 +457,7 @@ def __init__( | |||
new_module_name: str, | |||
old_module_name: str, | |||
deadline: str, | |||
broken_module_exception: Optional[BaseException], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type is optional but this argument isn't optional(?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just marked it as it could be None...that doesn't mean you don't have to mandatorily state whether it's None or not...is that weird? I can make it None by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's not that weird
Automerge cancelled: A required status check is not present. Missing statuses: ['Typescript lint check', 'Typescript tests', 'Typescript tests coverage'] |
…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.
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: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 #4106.
Fixes #4291.