Skip to content

Commit b86fbd1

Browse files
committed
fix: use from __future__ import annotations with TYPE_CHECKING guard
Add from __future__ import annotations to all 12 files so that type hints are treated as strings at runtime (fixing Python 3.10 NameError). Keep TYPE_CHECKING guard for DAGCircuit import to satisfy ruff F821. This matches the pattern used in basepasses.py and layout.py. Also fixes contains_instruction.py module docstring (was copy-paste from fixed_point.py).
1 parent 7d5a06c commit b86fbd1

12 files changed

Lines changed: 26 additions & 1 deletion

qiskit/transpiler/passes/analysis/count_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Count the operations in a DAG circuit."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/analysis/count_ops_longest_path.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Count the operations on the longest path in a DAGCircuit."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/analysis/dag_longest_path.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Return the longest path in a :class:`.DAGCircuit` as a list of DAGNodes."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/analysis/depth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Calculate the depth of a DAG circuit."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/analysis/num_qubits.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Calculate the number of qubits of a DAG circuit."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/analysis/num_tensor_factors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212

1313
"""Calculate the number of tensor factors of a DAG circuit."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:
1820
from qiskit.dagcircuit import DAGCircuit
21+
1922
from qiskit.transpiler.basepasses import AnalysisPass
2023

2124

qiskit/transpiler/passes/analysis/resource_estimation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Automatically require analysis passes for resource estimation."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/analysis/size.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Calculate the size of a DAG circuit."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/analysis/width.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"""Calculate the width of a DAG circuit."""
1414

15+
from __future__ import annotations
16+
1517
from typing import TYPE_CHECKING
1618

1719
if TYPE_CHECKING:

qiskit/transpiler/passes/utils/contains_instruction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
"""Check if a property reached a fixed point."""
13+
"""Check if the DAG contains a specific instruction."""
14+
15+
from __future__ import annotations
1416

1517
from collections.abc import Iterable
1618
from typing import TYPE_CHECKING

0 commit comments

Comments
 (0)