quantumlib / Cirq

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

Add module import linter in codebase #4863

Open MichaelBroughton opened 2 years ago

MichaelBroughton commented 2 years ago

Is your feature request related to a use case or problem? Please describe. Right now a lot of modules (in particular tests) are pretty free form with how they do imports. It's a good practice to import modules wherever possible.

bad:

from cirq.devices import GridQubit

good:

from cirq import devices

devices.GridQubit(whatever)

Describe the solution you'd like We should add a new plugin to pylint (or install an existing one) that catches non module imports where it makes sense. Some exceptions might be __init__ modules or typing imports and vendor modules that should just do import cirq everywhere.

maffoo commented 2 years ago

+1 to cleaning up import ... vs from ... import ... styles.

I'd add that having the formatting script also sort imports would be helpful (alphabetizing, grouping and ordering stdlib vs 3rd party vs cirq imports, etc). We have had good luck using isort internally.

smadhuk commented 2 years ago

Hi, could I grab this issue?

vtomole commented 2 years ago

@smadhuk I've assigned it to you?