From 92e78ef72a0f8aaaa57c4ca7f97e7646ace57c64 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Thu, 6 Jun 2024 21:53:46 +0100 Subject: [PATCH] Bump pylint to 3.2.2 (#12520) * Bump pylint to 3.2.2 This upgrades pylint to a version compatible with Python 3.8 through 3.12, like Qiskit. There are a couple of false positives (pylint is incorrect about its `use-yield-from` in the cases it flags), and has included a couple of new stylistic opinions that are not necessary to enforce. The `possibly-used-before-assignment` lint is quite possibly a good one, but there are far too many instances in the Qiskit codebase right now to fix, whereas our current version of pylint is preventing us from running it with Python 3.12. * Update requirements-dev.txt Co-authored-by: Pierre Sassoulas * Remove suppressions fixed in pylint 3.2.3 --------- Co-authored-by: Pierre Sassoulas Co-authored-by: Matthew Treinish --- pyproject.toml | 2 ++ qiskit/transpiler/passmanager.py | 4 ++-- qiskit/visualization/circuit/text.py | 8 +------- requirements-dev.txt | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 35a14a5524ba..6e57fa53a7e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -213,6 +213,7 @@ disable = [ "docstring-first-line-empty", # relax docstring style "import-outside-toplevel", "import-error", # overzealous with our optionals/dynamic packages "nested-min-max", # this gives false equivalencies if implemented for the current lint version + "consider-using-max-builtin", "consider-using-min-builtin", # unnecessary stylistic opinion # TODO(#9614): these were added in modern Pylint. Decide if we want to enable them. If so, # remove from here and fix the issues. Else, move it above this section and add a comment # with the rationale @@ -222,6 +223,7 @@ disable = [ "no-member", "no-value-for-parameter", "not-context-manager", + "possibly-used-before-assignment", "unexpected-keyword-arg", "unnecessary-dunder-call", "unnecessary-lambda-assignment", diff --git a/qiskit/transpiler/passmanager.py b/qiskit/transpiler/passmanager.py index bb1344e34cba..96c0be11b448 100644 --- a/qiskit/transpiler/passmanager.py +++ b/qiskit/transpiler/passmanager.py @@ -18,7 +18,7 @@ import re from collections.abc import Iterator, Iterable, Callable from functools import wraps -from typing import Union, List, Any +from typing import Union, List, Any, TypeVar from qiskit.circuit import QuantumCircuit from qiskit.converters import circuit_to_dag, dag_to_circuit @@ -31,7 +31,7 @@ from .exceptions import TranspilerError from .layout import TranspileLayout, Layout -_CircuitsT = Union[List[QuantumCircuit], QuantumCircuit] +_CircuitsT = TypeVar("_CircuitsT", bound=Union[List[QuantumCircuit], QuantumCircuit]) class PassManager(BasePassManager): diff --git a/qiskit/visualization/circuit/text.py b/qiskit/visualization/circuit/text.py index c2846da0b758..bec1ccf4a3ee 100644 --- a/qiskit/visualization/circuit/text.py +++ b/qiskit/visualization/circuit/text.py @@ -739,13 +739,7 @@ def __init__( self._wire_map = {} self.cregbundle = cregbundle - if encoding: - self.encoding = encoding - else: - if sys.stdout.encoding: - self.encoding = sys.stdout.encoding - else: - self.encoding = "utf8" + self.encoding = encoding or sys.stdout.encoding or "utf8" self._nest_depth = 0 # nesting depth for control flow ops self._expr_text = "" # expression text to display diff --git a/requirements-dev.txt b/requirements-dev.txt index c75237e77edd..7c5a909bd395 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -17,8 +17,8 @@ black[jupyter]~=24.1 # # These versions are pinned precisely because pylint frequently includes new # on-by-default lint failures in new versions, which breaks our CI. -astroid==2.14.2 -pylint==2.16.2 +astroid==3.2.2 +pylint==3.2.3 ruff==0.0.267