Skip to content

Fix strict typecheck for cirq importers #6717

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
pavoljuhas opened this issue Sep 5, 2024 · 0 comments
Closed

Fix strict typecheck for cirq importers #6717

pavoljuhas opened this issue Sep 5, 2024 · 0 comments
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/health For CI/testing/release process/refactoring/technical debt items no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you.

Comments

@pavoljuhas
Copy link
Collaborator

Description of the issue

Clients importing from cirq fail strict type checking as follows:

$ mypy --strict -c "from cirq import Circuit"
<string>:1: error: Module "cirq" does not explicitly export attribute "Circuit"  [attr-defined]

This is because our typecheck setup in mypy.ini does not enforce no_implicit_reexport.

Solution

  1. add no_implicit_reexport = true to mypy.ini
  2. update __init__.py files to reexport symbols, ie, replace from foo import bar with from foo import bar as bar

Cirq version

1.4.1 at f56a799

@pavoljuhas pavoljuhas added kind/health For CI/testing/release process/refactoring/technical debt items good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. labels Sep 5, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
ashiq-firoz added a commit to ashiq-firoz/Cirq that referenced this issue Sep 8, 2024
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
…#6722)

* Enable and enforce the `no_implicit_reexport` mypy rule for cirq modules
* Update `__init__.py` files so they explicitly re-export public symbols, but
  do not re-export local symbols or submodules already in parent namespace
* Fix few instances of imports from incorrect modules

Fixes quantumlib#6717
---------

Co-authored-by: Pavol Juhas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/health For CI/testing/release process/refactoring/technical debt items no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you.
Projects
None yet
Development

No branches or pull requests

1 participant