]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Remove and dissallow unused type ignores (#2470)
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Tue, 29 Nov 2022 16:55:45 +0000 (10:55 -0600)
committerGitHub <noreply@github.com>
Tue, 29 Nov 2022 16:55:45 +0000 (16:55 +0000)
* Remove and dissallow unused type ignores

* add pragmas

* fix ignore

httpx/_config.py
httpx/_content.py
httpx/_status_codes.py
httpx/_transports/mock.py
setup.cfg
tests/test_config.py
tests/test_content.py

index f8f51b6c4102b2cf49971dfd7053a2ae1d888c9a..a4e8f6ce3a845bc7c8e32bffc2dc9be782bc7513 100644 (file)
@@ -1,5 +1,6 @@
 import os
 import ssl
+import sys
 import typing
 from pathlib import Path
 
@@ -125,15 +126,16 @@ class SSLConfig:
 
         # Signal to server support for PHA in TLS 1.3. Raises an
         # AttributeError if only read-only access is implemented.
-        try:
-            context.post_handshake_auth = True  # type: ignore
-        except AttributeError:  # pragma: no cover
-            pass
+        if sys.version_info >= (3, 8):  # pragma: no cover
+            try:
+                context.post_handshake_auth = True
+            except AttributeError:  # pragma: no cover
+                pass
 
         # Disable using 'commonName' for SSLContext.check_hostname
         # when the 'subjectAltName' extension isn't available.
         try:
-            context.hostname_checks_common_name = False  # type: ignore
+            context.hostname_checks_common_name = False
         except AttributeError:  # pragma: no cover
             pass
 
@@ -162,10 +164,10 @@ class SSLConfig:
             alpn_idents = ["http/1.1", "h2"] if self.http2 else ["http/1.1"]
             context.set_alpn_protocols(alpn_idents)
 
-        if hasattr(context, "keylog_filename"):  # pragma: no cover (Available in 3.8+)
+        if sys.version_info >= (3, 8):  # pragma: no cover
             keylogfile = os.environ.get("SSLKEYLOGFILE")
             if keylogfile and self.trust_env:
-                context.keylog_filename = keylogfile  # type: ignore
+                context.keylog_filename = keylogfile
 
         return context
 
index e0d0b60a182d7fede3dc3b52979931e29207ee5f..3cbca7ac691dc30e3e9e0655771ea6027974ccad 100644 (file)
@@ -189,7 +189,7 @@ def encode_request(
     Handles encoding the given `content`, `data`, `files`, and `json`,
     returning a two-tuple of (<headers>, <stream>).
     """
-    if data is not None and not isinstance(data, Mapping):  # type: ignore
+    if data is not None and not isinstance(data, Mapping):
         # We prefer to separate `content=<bytes|str|byte iterator|bytes aiterator>`
         # for raw request content, and `data=<form data>` for url encoded or
         # multipart form content.
index e5004412751353dadd8984f5cbb9d050ea7a6f57..671c30e1b80f82adebc3018b1e53a90054d93bfb 100644 (file)
@@ -22,10 +22,10 @@ class codes(IntEnum):
     """
 
     def __new__(cls, value: int, phrase: str = "") -> "codes":
-        obj = int.__new__(cls, value)  # type: ignore
+        obj = int.__new__(cls, value)
         obj._value_ = value
 
-        obj.phrase = phrase  # type: ignore
+        obj.phrase = phrase  # type: ignore[attr-defined]
         return obj
 
     def __str__(self) -> str:
index 8a70dfe142634cc1659db176540a72caa3c85346..1434166dd5ef6670a0f4d81c9c44555e07f93d80 100644 (file)
@@ -29,6 +29,6 @@ class MockTransport(AsyncBaseTransport, BaseTransport):
 
         # https://simonwillison.net/2020/Sep/2/await-me-maybe/
         if asyncio.iscoroutine(response):
-            response = await response  # type: ignore[func-returns-value,assignment]
+            response = await response
 
         return response
index 27f18be4ccac01e0a196f8081f62a211791ffb59..3e2a335750acaeb4b1d3fd056502035721e0018a 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -8,6 +8,7 @@ disallow_any_generics = True
 ignore_missing_imports = True
 no_implicit_optional = True
 show_error_codes = True
+warn_unused_ignores = True
 warn_unused_configs = True
 disallow_subclassing_any = True
 check_untyped_defs = True
index 4056658a6a3317839f1b1179494dc3391cf5c075..d496cd4a0eb1d9af996c03250ef1c4580fdd42d3 100644 (file)
@@ -178,25 +178,26 @@ def test_timeout_repr():
 )
 @pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
 def test_ssl_config_support_for_keylog_file(tmpdir, monkeypatch):  # pragma: no cover
-    with monkeypatch.context() as m:
-        m.delenv("SSLKEYLOGFILE", raising=False)
+    if sys.version_info > (3, 8):
+        with monkeypatch.context() as m:
+            m.delenv("SSLKEYLOGFILE", raising=False)
 
-        context = httpx.create_ssl_context(trust_env=True)
+            context = httpx.create_ssl_context(trust_env=True)
 
-        assert context.keylog_filename is None  # type: ignore
+            assert context.keylog_filename is None
 
-    filename = str(tmpdir.join("test.log"))
+        filename = str(tmpdir.join("test.log"))
 
-    with monkeypatch.context() as m:
-        m.setenv("SSLKEYLOGFILE", filename)
+        with monkeypatch.context() as m:
+            m.setenv("SSLKEYLOGFILE", filename)
 
-        context = httpx.create_ssl_context(trust_env=True)
+            context = httpx.create_ssl_context(trust_env=True)
 
-        assert context.keylog_filename == filename  # type: ignore
+            assert context.keylog_filename == filename
 
-        context = httpx.create_ssl_context(trust_env=False)
+            context = httpx.create_ssl_context(trust_env=False)
 
-        assert context.keylog_filename is None  # type: ignore
+            assert context.keylog_filename is None
 
 
 def test_proxy_from_url():
index 235e63f4030d41583c446180118ab236afd29d06..7b13090b1e1113ec2aa1029587ac6568aec73c85 100644 (file)
@@ -105,7 +105,7 @@ async def test_iterator_content():
 
     # Support 'data' for compat with requests.
     with pytest.warns(DeprecationWarning):
-        headers, stream = encode_request(data=hello_world())  # type: ignore
+        headers, stream = encode_request(data=hello_world())
     assert isinstance(stream, typing.Iterable)
     assert not isinstance(stream, typing.AsyncIterable)
 
@@ -135,7 +135,7 @@ async def test_aiterator_content():
 
     # Support 'data' for compat with requests.
     with pytest.warns(DeprecationWarning):
-        headers, stream = encode_request(data=hello_world())  # type: ignore
+        headers, stream = encode_request(data=hello_world())
     assert not isinstance(stream, typing.Iterable)
     assert isinstance(stream, typing.AsyncIterable)