Skip to content

Commit ea7c94e

Browse files
authored
ruff - enable and fix a series of UPNNN rules (#7748)
New ruff linter rules activated and fixed here: - useless-object-inheritance (UP004) - native-literals (UP018) - yield-in-for-loop (UP028) - extraneous-parentheses (UP034) - deprecated-import (UP035) Partially implements #7505
1 parent c444498 commit ea7c94e

File tree

402 files changed

+790
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

402 files changed

+790
-560
lines changed

benchmarks/circuit_construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import itertools
15-
from typing import Sequence
15+
from collections.abc import Sequence
1616

1717
import cirq
1818

benchmarks/randomized_benchmarking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import functools
16-
from typing import Sequence
16+
from collections.abc import Sequence
1717

1818
import numpy as np
1919

cirq-aqt/cirq_aqt/aqt_device.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
from __future__ import annotations
2828

2929
import json
30+
from collections.abc import Iterable, Sequence
3031
from enum import Enum
31-
from typing import Any, cast, Iterable, Sequence
32+
from typing import Any, cast
3233

3334
import networkx as nx
3435
import numpy as np

cirq-aqt/cirq_aqt/aqt_device_metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from __future__ import annotations
1818

19-
from typing import Any, Iterable, Mapping
19+
from collections.abc import Iterable, Mapping
20+
from typing import Any
2021

2122
import networkx as nx
2223

cirq-aqt/cirq_aqt/aqt_sampler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import json
2828
import time
2929
import uuid
30-
from typing import Callable, cast, Literal, Sequence, TypedDict
30+
from collections.abc import Callable, Sequence
31+
from typing import cast, Literal, TypedDict
3132
from urllib.parse import urljoin
3233

3334
import numpy as np

cirq-core/cirq/_compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import sys
2828
import traceback
2929
import warnings
30+
from collections.abc import Callable, Iterator
3031
from types import ModuleType
31-
from typing import Any, Callable, Iterator, overload, TypeVar
32+
from typing import Any, overload, TypeVar
3233

3334
import numpy as np
3435
import pandas as pd

cirq-core/cirq/_compat_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import traceback
2626
import types
2727
import warnings
28+
from collections.abc import Callable
2829
from importlib.machinery import ModuleSpec
2930
from types import ModuleType
30-
from typing import Any, Callable
31+
from typing import Any
3132
from unittest import mock
3233

3334
import duet
@@ -159,7 +160,7 @@ def f(a, b):
159160

160161

161162
def test_deprecated_with_property():
162-
class AClass(object):
163+
class AClass:
163164
def __init__(self, a):
164165
self.a = a
165166

cirq-core/cirq/_import.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
import importlib
1818
import sys
19+
from collections.abc import Callable
1920
from contextlib import contextmanager
2021
from importlib import abc
2122
from importlib.abc import Loader
2223
from importlib.machinery import ModuleSpec
2324
from types import ModuleType
24-
from typing import Any, Callable, cast
25+
from typing import Any, cast
2526

2627

2728
class InstrumentedFinder(abc.MetaPathFinder):

cirq-core/cirq/circuits/_bucket_priority_queue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import Any, Generic, Iterable, Iterator, TypeVar
17+
from collections.abc import Iterable, Iterator
18+
from typing import Any, Generic, TypeVar
1819

1920
TItem = TypeVar('TItem')
2021

cirq-core/cirq/circuits/circuit.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,18 @@
2727
import itertools
2828
import math
2929
from collections import defaultdict
30-
from types import NotImplementedType
31-
from typing import (
32-
AbstractSet,
33-
Any,
30+
from collections.abc import (
3431
Callable,
35-
cast,
3632
Hashable,
3733
Iterable,
3834
Iterator,
3935
Mapping,
4036
MutableSequence,
41-
overload,
42-
Self,
4337
Sequence,
44-
TYPE_CHECKING,
45-
TypeVar,
46-
Union,
38+
Set,
4739
)
40+
from types import NotImplementedType
41+
from typing import Any, cast, overload, Self, TYPE_CHECKING, TypeVar, Union
4842

4943
import networkx
5044
import numpy as np
@@ -1341,7 +1335,7 @@ def _is_parameterized_(self) -> bool:
13411335
protocols.is_parameterized(tag) for tag in self.tags
13421336
)
13431337

1344-
def _parameter_names_(self) -> AbstractSet[str]:
1338+
def _parameter_names_(self) -> Set[str]:
13451339
op_params = {name for op in self.all_operations() for name in protocols.parameter_names(op)}
13461340
tag_params = {name for tag in self.tags for name in protocols.parameter_names(tag)}
13471341
return op_params | tag_params
@@ -1845,7 +1839,7 @@ def __init__(
18451839
self._frozen: cirq.FrozenCircuit | None = None
18461840
self._is_measurement: bool | None = None
18471841
self._is_parameterized: bool | None = None
1848-
self._parameter_names: AbstractSet[str] | None = None
1842+
self._parameter_names: Set[str] | None = None
18491843
if not contents:
18501844
return
18511845
flattened_contents = tuple(ops.flatten_to_ops_or_moments(contents))
@@ -1954,7 +1948,7 @@ def _is_parameterized_(self) -> bool:
19541948
self._is_parameterized = super()._is_parameterized_()
19551949
return self._is_parameterized
19561950

1957-
def _parameter_names_(self) -> AbstractSet[str]:
1951+
def _parameter_names_(self) -> Set[str]:
19581952
if self._parameter_names is None:
19591953
self._parameter_names = super()._parameter_names_()
19601954
return self._parameter_names

0 commit comments

Comments
 (0)