From 041877bfc436cb7d8ddc799ab663ad1e62c08ff7 Mon Sep 17 00:00:00 2001
From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Date: Mon, 20 Feb 2023 11:50:15 -0600
Subject: [PATCH] Upgrade Pylint to 2.16.2 (#9615)

* Upgrade Pylint to 2.16.2

* Clarify we don't neccessarily want to enable everything

* Locally disable some checks that only fail in CI and seem bogus

Maybe related to what Python version Pylint is run with
---
 .pylintrc                                     | 89 ++++++++-----------
 .../opflow/converters/pauli_basis_change.py   |  4 +-
 requirements-dev.txt                          |  4 +-
 test/python/pulse/test_transforms.py          | 10 ++-
 4 files changed, 50 insertions(+), 57 deletions(-)

diff --git a/.pylintrc b/.pylintrc
index e88b937da3ee..4baca04b2623 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -34,8 +34,8 @@ unsafe-load-any-extension=no
 # be loaded. Extensions are loading into the active Python interpreter and may
 # run arbitrary code
 extension-pkg-allow-list=retworkx, numpy, tweedledum, qiskit._accelerate, rustworkx
-generated-modules=retworkx.visualization,retwork.visit
-ignore-modules=retworkx,retworkx.visualization,retworkx.visit
+generated-members=retworkx.visualization,retwork.visit
+ignored-modules=retworkx,retworkx.visualization,retworkx.visit
 
 [MESSAGES CONTROL]
 
@@ -59,7 +59,6 @@ enable=use-symbolic-message-instead
 # no Warning level messages displayed, use"--disable=all --enable=classes
 # --disable=W"
 disable=spelling,       # way too noisy
-    no-self-use,        # disabled as it is too verbose
     fixme,              # disabled as TODOs would show up as warnings
     protected-access,   # disabled as we don't follow the public vs private
                         # convention strictly
@@ -73,11 +72,41 @@ disable=spelling,       # way too noisy
     no-else-return,     # relax "elif" after a clause with a return
     docstring-first-line-empty, # relax docstring style
     import-outside-toplevel,
-    bad-continuation, bad-whitespace, # differences of opinion with black
-    import-error        # overzealous with our optionals/dynamic packages
-
-
-
+    import-error,        # overzealous with our optionals/dynamic packages
+
+    # 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.
+    arguments-renamed,
+    broad-exception-raised,
+    consider-iterating-dictionary,
+    consider-using-dict-items,
+    consider-using-enumerate,
+    consider-using-f-string,
+    consider-using-from-import,
+    modified-iterating-list,
+    nested-min-max,
+    no-member,
+    no-value-for-parameter,
+    non-ascii-name,
+    not-context-manager,
+    pointless-exception-statement,
+    superfluous-parens,
+    unknown-option-value,
+    unexpected-keyword-arg,
+    unnecessary-dict-index-lookup,
+    unnecessary-direct-lambda-call,
+    unnecessary-dunder-call,
+    unnecessary-ellipsis,
+    unnecessary-lambda-assignment,
+    unnecessary-list-index-lookup,
+    unspecified-encoding,
+    unsupported-assignment-operation,
+    use-dict-literal,
+    use-list-literal,
+    use-implicit-booleaness-not-comparison,
+    use-maxsplit-arg,
+    used-before-assignment,
 
 [REPORTS]
 
@@ -86,12 +115,6 @@ disable=spelling,       # way too noisy
 # mypackage.mymodule.MyReporterClass.
 output-format=text
 
-# Put messages in a separate file for each module / package specified on the
-# command line instead of printing them on stdout. Reports (if any) will be
-# written in a file name "pylint_global.[txt|html]". This option is deprecated
-# and it will be removed in Pylint 2.0.
-files-output=no
-
 # Tells whether to display a full report or only the messages
 reports=yes
 
@@ -140,63 +163,33 @@ property-classes=abc.abstractproperty
 # Regular expression matching correct module names
 module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
 
-# Naming hint for module names
-module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
-
 # Regular expression matching correct constant names
 const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
 
-# Naming hint for constant names
-const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
-
 # Regular expression matching correct class names
 class-rgx=[A-Z_][a-zA-Z0-9]+$
 
-# Naming hint for class names
-class-name-hint=[A-Z_][a-zA-Z0-9]+$
-
 # Regular expression matching correct function names
 function-rgx=[a-z_][a-z0-9_]{2,30}$
 
-# Naming hint for function names
-function-name-hint=[a-z_][a-z0-9_]{2,30}$
-
 # Regular expression matching correct method names
 method-rgx=(([a-z_][a-z0-9_]{2,49})|(assert[A-Z][a-zA-Z0-9]{2,43})|(test_[_a-zA-Z0-9]{2,}))$
 
-# Naming hint for method names
-method-name-hint=[a-z_][a-z0-9_]{2,30}$ or camelCase `assert*` in tests.
-
 # Regular expression matching correct attribute names
 attr-rgx=[a-z_][a-z0-9_]{2,30}$
 
-# Naming hint for attribute names
-attr-name-hint=[a-z_][a-z0-9_]{2,30}$
-
 # Regular expression matching correct argument names
 argument-rgx=[a-z_][a-z0-9_]{2,30}|ax|dt$
 
-# Naming hint for argument names
-argument-name-hint=[a-z_][a-z0-9_]{2,30}$
-
 # Regular expression matching correct variable names
 variable-rgx=[a-z_][a-z0-9_]{1,30}$
 
-# Naming hint for variable names
-variable-name-hint=[a-z_][a-z0-9_]{1,30}$
-
 # Regular expression matching correct class attribute names
 class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
 
-# Naming hint for class attribute names
-class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
-
 # Regular expression matching correct inline iteration names
 inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
 
-# Naming hint for inline iteration names
-inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
-
 # Regular expression which should only match function or class names that do
 # not require a docstring.
 no-docstring-rgx=^_
@@ -224,12 +217,6 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
 # else.
 single-line-if-stmt=no
 
-# List of optional constructs for which whitespace checking is disabled. `dict-
-# separator` is used to allow tabulation in dicts, etc.: {1  : 1,\n222: 2}.
-# `trailing-comma` allows a space between comma and closing bracket: (a, ).
-# `empty-line` allows space-only lines.
-no-space-check=trailing-comma,dict-separator
-
 # Maximum number of lines in a module
 max-module-lines=1000
 
@@ -426,4 +413,4 @@ analyse-fallback-blocks=no
 
 # Exceptions that will emit a warning when being caught. Defaults to
 # "Exception"
-overgeneral-exceptions=Exception
+overgeneral-exceptions=builtins.Exception
diff --git a/qiskit/opflow/converters/pauli_basis_change.py b/qiskit/opflow/converters/pauli_basis_change.py
index cdc78c227d26..a5927e38aca4 100644
--- a/qiskit/opflow/converters/pauli_basis_change.py
+++ b/qiskit/opflow/converters/pauli_basis_change.py
@@ -346,7 +346,9 @@ def get_diagonalizing_clifford(self, pauli: Union[Pauli, PauliOp]) -> OperatorBa
         y_to_x_origin = tensorall(
             [S if has_y else I for has_y in reversed(np.logical_and(pauli.x, pauli.z))]
         ).adjoint()
-        x_to_z_origin = tensorall([H if has_x else I for has_x in reversed(pauli.x)])
+        x_to_z_origin = tensorall(  # pylint: disable=assignment-from-no-return
+            [H if has_x else I for has_x in reversed(pauli.x)]
+        )
         return x_to_z_origin.compose(y_to_x_origin)
 
     def pad_paulis_to_equal_length(
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 52defd0584dd..54d0f552546d 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -9,8 +9,8 @@ matplotlib>=3.3
 pillow>=4.2.1
 black[jupyter]~=22.0
 pydot
-astroid==2.5.6
-pylint==2.8.3
+astroid==2.14.2
+pylint==2.16.2
 stestr>=2.0.0,!=4.0.0
 pylatexenc>=1.4
 ddt>=1.2.0,!=1.4.0,!=1.4.3
diff --git a/test/python/pulse/test_transforms.py b/test/python/pulse/test_transforms.py
index e19d024c2b4f..ce968e04e31b 100644
--- a/test/python/pulse/test_transforms.py
+++ b/test/python/pulse/test_transforms.py
@@ -271,7 +271,9 @@ def test_padding_schedule(self):
             | Delay(delay, DriveChannel(0))
             | Delay(delay, DriveChannel(0)).shift(20)
             | Delay(delay, DriveChannel(1))
-            | Delay(2 * delay, DriveChannel(1)).shift(20)
+            | Delay(  # pylint: disable=unsupported-binary-operation
+                2 * delay, DriveChannel(1)
+            ).shift(20)
         )
 
         self.assertEqual(transforms.pad(sched), ref_sched)
@@ -294,7 +296,9 @@ def test_padding_schedule_inverse_order(self):
             | Delay(delay, DriveChannel(0))
             | Delay(delay, DriveChannel(0)).shift(20)
             | Delay(delay, DriveChannel(1))
-            | Delay(2 * delay, DriveChannel(1)).shift(20)
+            | Delay(  # pylint: disable=unsupported-binary-operation
+                2 * delay, DriveChannel(1)
+            ).shift(20)
         )
 
         self.assertEqual(transforms.pad(sched), ref_sched)
@@ -319,7 +323,7 @@ def test_padding_until_greater(self):
             sched
             | Delay(delay, DriveChannel(0))
             | Delay(30, DriveChannel(0)).shift(20)
-            | Delay(40, DriveChannel(1)).shift(10)
+            | Delay(40, DriveChannel(1)).shift(10)  # pylint: disable=unsupported-binary-operation
         )
 
         self.assertEqual(transforms.pad(sched, until=50), ref_sched)