Repository: open-telemetry/opentelemetry-python-contrib

Issue:
Upgrade pylint to 2.11.0
Proposing we keep up with pylint and upgrade to 2.11.0. The following needs to be done to clean up the code:

- [x] #692
- [ ] #684
- [x] #694
- [x] #688
- [x] #690


Discussion:
There's an open issue regarding this here https://github.com/PyCQA/pylint/issues/4972

Resolving patch:
diff --git a/exporter/opentelemetry-exporter-richconsole/setup.py b/exporter/opentelemetry-exporter-richconsole/setup.py
--- a/exporter/opentelemetry-exporter-richconsole/setup.py
+++ b/exporter/opentelemetry-exporter-richconsole/setup.py
@@ -21,7 +21,7 @@
     BASE_DIR, "src", "opentelemetry", "exporter", "richconsole", "version.py"
 )
 PACKAGE_INFO = {}
-with open(VERSION_FILENAME) as f:
+with open(VERSION_FILENAME, encoding="utf-8") as f:
     exec(f.read(), PACKAGE_INFO)
 
 setuptools.setup(version=PACKAGE_INFO["__version__"])
diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py
--- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py
+++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py
@@ -131,6 +131,7 @@ def _generate_sql_comment(**meta):
 
     # Sort the keywords to ensure that caching works and that testing is
     # deterministic. It eases visual inspection as well.
+    # pylint: disable=consider-using-f-string
     return (
         " /*"
         + _KEY_VALUE_DELIMITER.join(


Test patch:
diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py
--- a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py
+++ b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py
@@ -507,6 +507,7 @@ def __init__(self, database, server_port, server_host, user):
         self.server_host = server_host
         self.user = user
 
+    # pylint: disable=no-self-use
     async def release(self, conn):
         return conn
 
@@ -542,11 +543,11 @@ def __init__(self, database, server_port, server_host, user):
             database, server_port, server_host, user
         )
 
-    # pylint: disable=no-self-use
     def cursor(self):
         coro = self._cursor()
         return _ContextManager(coro)  # pylint: disable=no-value-for-parameter
 
+    # pylint: disable=no-self-use
     async def _cursor(self):
         return MockCursor()
 
@@ -585,6 +586,7 @@ async def __aenter__(self):
 
 
 class AiopgPoolMock:
+    # pylint: disable=no-self-use
     async def release(self, conn):
         return conn
 
@@ -592,6 +594,7 @@ def acquire(self):
         coro = self._acquire()
         return _PoolAcquireContextManager(coro, self)
 
+    # pylint: disable=no-self-use
     async def _acquire(self):
         return AiopgConnectionMock()
 
diff --git a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py
--- a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py
+++ b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py
@@ -310,10 +310,10 @@ def test_traceresponse_header(self):
         self.assertEqual(response_body["body"], b"*")
         self.assertEqual(response_start["status"], 200)
 
-        traceresponse = "00-{0}-{1}-01".format(
-            format_trace_id(span.get_span_context().trace_id),
-            format_span_id(span.get_span_context().span_id),
-        )
+        trace_id = format_trace_id(span.get_span_context().trace_id)
+        span_id = format_span_id(span.get_span_context().span_id)
+        traceresponse = f"00-{trace_id}-{span_id}-01"
+
         self.assertListEqual(
             response_start["headers"],
             [
@@ -423,10 +423,10 @@ def test_websocket_traceresponse_header(self):
         span = self.memory_exporter.get_finished_spans()[-1]
         self.assertEqual(trace_api.SpanKind.SERVER, span.kind)
 
-        traceresponse = "00-{0}-{1}-01".format(
-            format_trace_id(span.get_span_context().trace_id),
-            format_span_id(span.get_span_context().span_id),
-        )
+        trace_id = format_trace_id(span.get_span_context().trace_id)
+        span_id = format_span_id(span.get_span_context().span_id)
+        traceresponse = f"00-{trace_id}-{span_id}-01"
+
         self.assertListEqual(
             socket_send["headers"],
             [
diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py
--- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py
+++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py
@@ -368,12 +368,11 @@ async def test_trace_response_headers(self):
             response["Access-Control-Expose-Headers"],
             "traceresponse",
         )
+        trace_id = format_trace_id(span.get_span_context().trace_id)
+        span_id = format_span_id(span.get_span_context().span_id)
         self.assertEqual(
             response["traceresponse"],
-            "00-{}-{}-01".format(
-                format_trace_id(span.get_span_context().trace_id),
-                format_span_id(span.get_span_context().span_id),
-            ),
+            f"00-{trace_id}-{span_id}-01",
         )
         self.memory_exporter.clear()
 
diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py b/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py
--- a/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py
+++ b/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py
@@ -106,7 +106,7 @@ def test_set_not_recording(self):
     def test_get_many_none_found(self):
         client = self.make_client([b"END\r\n"])
         result = client.get_many([b"key1", b"key2"])
-        assert result == {}
+        assert not result
 
         spans = self.memory_exporter.get_finished_spans()
 
@@ -116,7 +116,7 @@ def test_get_multi_none_found(self):
         client = self.make_client([b"END\r\n"])
         # alias for get_many
         result = client.get_multi([b"key1", b"key2"])
-        assert result == {}
+        assert not result
 
         spans = self.memory_exporter.get_finished_spans()