Skip to content

Commit

Permalink
Remove dependency on the flynt tool (#6164)
Browse files Browse the repository at this point in the history
- pylint - enable `consider-using-f-string` check
- Test package metadata with numpy rather than flynt
- Fix CI complains on test coverage - fix markup for ignoring coverage
- Temporarily disable consider-using-f-string pylint and add TODO-s to fix later
- Format touched files with black-23.3.0

Partially fixes #6171

---------

Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
  • Loading branch information
pavoljuhas and tanujkhattar committed Jul 12, 2023
1 parent 3fe3438 commit 8e70f77
Show file tree
Hide file tree
Showing 74 changed files with 275 additions and 48 deletions.
16 changes: 5 additions & 11 deletions cirq-core/cirq/_compat_test.py
Expand Up @@ -200,9 +200,8 @@ def old_func(*args, **kwargs):

with pytest.raises(AssertionError, match='deadline should match vX.Y'):
# pylint: disable=unused-variable
# coverage: ignore
@deprecated(deadline='invalid', fix='Roll some dice.')
def badly_deprecated_func(*args, **kwargs):
def badly_deprecated_func(*args, **kwargs): # pragma: no cover
return new_func(*args, **kwargs)

# pylint: enable=unused-variable
Expand Down Expand Up @@ -258,8 +257,7 @@ def f(new_count):
rewrite=lambda args, kwargs: (args, {'new_count': kwargs['double_count'] * 2}),
)
# pylint: disable=unused-variable
# coverage: ignore
def f_with_badly_deprecated_param(new_count):
def f_with_badly_deprecated_param(new_count): # pragma: no cover
return new_count

# pylint: enable=unused-variable
Expand Down Expand Up @@ -371,9 +369,8 @@ class OldClass(NewClass):

with pytest.raises(AssertionError, match='deadline should match vX.Y'):
# pylint: disable=unused-variable
# coverage: ignore
@deprecated_class(deadline='invalid', fix='theFix', name='foo')
class BadlyDeprecatedClass(NewClass):
class BadlyDeprecatedClass(NewClass): # pragma: no cover
...

# pylint: enable=unused-variable
Expand Down Expand Up @@ -619,8 +616,6 @@ def subprocess_context(test_func):
"it to this method?"
)

import os

ctx = multiprocessing.get_context('spawn' if os.name == 'nt' else 'fork')

exception = ctx.Queue()
Expand All @@ -632,8 +627,7 @@ def isolated_func(*args, **kwargs):
p.start()
p.join()
result = exception.get()
if result:
# coverage: ignore
if result: # pragma: no cover
ex_type, msg, ex_trace = result
if ex_type == "Skipped":
warnings.warn(f"Skipping: {ex_type}: {msg}\n{ex_trace}")
Expand Down Expand Up @@ -727,7 +721,7 @@ def _test_metadata_search_path_inner(): # pragma: no cover
# pylint: disable=unused-import
import cirq.testing._compat_test_data.module_a

assert importlib.metadata.metadata('flynt')
assert importlib.metadata.metadata('numpy')


def test_metadata_distributions_after_deprecated_submodule():
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/circuits/_block_diagram_drawer_test.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

import itertools

import pytest
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/circuits/circuit_operation.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""A structure for encapsulating entire circuits in an operation.
A CircuitOperation is an Operation object that wraps a FrozenCircuit. When
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/circuits/text_diagram_drawer_test.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from unittest import mock
import pytest

Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/contrib/acquaintance/bipartite.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

import enum
import itertools
from typing import Dict, Sequence, Tuple, Union, TYPE_CHECKING
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/contrib/acquaintance/devices.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Union, TYPE_CHECKING

import abc
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/contrib/acquaintance/gates.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

import functools
import itertools
import math
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/contrib/acquaintance/testing.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import cast, Sequence, TYPE_CHECKING

from cirq import devices, ops, protocols
Expand Down
5 changes: 3 additions & 2 deletions cirq-core/cirq/contrib/paulistring/recombine.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Any, Callable, Iterable, Sequence, Tuple, Union, cast, List

from cirq import circuits, ops, protocols
Expand All @@ -27,7 +30,6 @@ def _sorted_best_string_placements(
output_ops: Sequence[ops.Operation],
key: Callable[[Any], ops.PauliStringPhasor] = lambda node: node.val,
) -> List[Tuple[ops.PauliStringPhasor, int, circuitdag.Unique[ops.PauliStringPhasor]]]:

sort_key = lambda placement: (-len(placement[0].pauli_string), placement[1])

node_maxes = []
Expand Down Expand Up @@ -84,7 +86,6 @@ def move_pauli_strings_into_circuit(
# Pick the Pauli string that can be moved furthest through
# the Clifford circuit
for best_string_op, best_index, best_node in placements:

assert (
best_index <= last_index
), "Unexpected insertion index order, {} >= {}, len: {}".format(
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/contrib/qasm_import/_parser.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

import functools
import operator
from typing import Any, Callable, cast, Dict, Iterable, List, Optional, Union, TYPE_CHECKING
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/contrib/qasm_import/_parser_test.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Callable

import numpy as np
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/contrib/qcircuit/qcircuit_test.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

import cirq
import cirq.contrib.qcircuit as ccq
import cirq.testing as ct
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/contrib/quirk/quirk_gate.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Any, Callable, cast, Dict, Optional, Union

import numpy as np
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/devices/noise_model.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Any, Dict, Iterable, Sequence, TYPE_CHECKING, Union, Callable

from cirq import ops, protocols, value
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/linalg/diagonalize_test.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

import random
from typing import Tuple, Optional

Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/linalg/transformations.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""Utility methods for transforming matrices or vectors."""

import dataclasses
Expand Down
4 changes: 3 additions & 1 deletion cirq-core/cirq/ops/clifford_gate.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union


Expand Down Expand Up @@ -434,7 +437,6 @@ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
def _act_on_(
self, sim_state: 'cirq.SimulationStateBase', qubits: Sequence['cirq.Qid']
) -> Union[NotImplementedType, bool]:

# Note the computation complexity difference between _decompose_ and _act_on_.
# Suppose this Gate has `m` qubits, args has `n` qubits, and the decomposition of
# this operation into `k` operations:
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/common_gate_families.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""Common Gate Families used in cirq-core"""

from typing import Any, cast, Optional, Type, Union
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/ops/common_gates.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""Quantum gates that are commonly used in the literature.
This module creates Gate instances for the following gates:
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/diagonal_gate.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""Creates the gate instance for any number qubits diagonal gate.
The gate is used to create a (2^n)x(2^n) matrix with the diagonal elements
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/gateset_test.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Tuple, List, cast
import re
import pytest
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/ops/linear_combinations.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from collections import defaultdict
from typing import (
AbstractSet,
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/raw_types.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""Basic types defining qubits, gates, and operations."""

import abc
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/three_qubit_gates.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""Common quantum gates that target three qubits."""

from typing import (
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/ops/two_qubit_diagonal_gate.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""Creates the gate instance for a two qubit diagonal gate.
The gate is used to create a 4x4 matrix with the diagonal elements
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/protocols/apply_channel_protocol.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""A protocol for implementing high performance channel evolutions."""

from typing import Any, Iterable, Optional, Sequence, TypeVar, Tuple, Union
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/protocols/apply_mixture_protocol.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""A protocol for implementing high performance mixture evolutions."""

from typing import Any, cast, Iterable, Optional, Tuple, TypeVar, Union
Expand Down
5 changes: 5 additions & 0 deletions cirq-core/cirq/protocols/apply_unitary_protocol.py
Expand Up @@ -11,7 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

"""A protocol for implementing high performance unitary left-multiplies."""

import warnings
from typing import Any, cast, Iterable, Optional, Sequence, Tuple, TYPE_CHECKING, TypeVar, Union

Expand Down
5 changes: 4 additions & 1 deletion cirq-core/cirq/protocols/circuit_diagram_info_protocol.py
Expand Up @@ -11,6 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

import re
from fractions import Fraction
from typing import (
Expand Down Expand Up @@ -122,7 +126,6 @@ def _wire_symbols_including_formatted_exponent(
return result

def _formatted_exponent(self, args: 'cirq.CircuitDiagramInfoArgs') -> Optional[str]:

if protocols.is_parameterized(self.exponent):
name = str(self.exponent)
return f'({name})' if _is_exposed_formula(name) else name
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/protocols/inverse_protocol.py
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#6171): enable the check and fix pylint errors
# pylint: disable=consider-using-f-string

from typing import Any, List, overload, Tuple, TYPE_CHECKING, TypeVar, Union, Iterable

from cirq import ops
Expand Down

0 comments on commit 8e70f77

Please sign in to comment.