quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.24k stars 1.01k forks source link

Fix strict typecheck for cirq importers #6717

Closed pavoljuhas closed 2 weeks ago

pavoljuhas commented 3 weeks ago

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 f56a799c4dff188df9cb91c2de524a7953938e48