From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Tue, 29 Nov 2022 16:55:45 +0000 (-0600) Subject: Remove and dissallow unused type ignores (#2470) X-Git-Tag: 0.23.2~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69e13cbc393ee13624d0e4aa4b6f861a95e3f91c;p=thirdparty%2Fhttpx.git Remove and dissallow unused type ignores (#2470) * Remove and dissallow unused type ignores * add pragmas * fix ignore --- diff --git a/httpx/_config.py b/httpx/_config.py index f8f51b6c..a4e8f6ce 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -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 diff --git a/httpx/_content.py b/httpx/_content.py index e0d0b60a..3cbca7ac 100644 --- a/httpx/_content.py +++ b/httpx/_content.py @@ -189,7 +189,7 @@ def encode_request( Handles encoding the given `content`, `data`, `files`, and `json`, returning a two-tuple of (, ). """ - 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=` # for raw request content, and `data=
` for url encoded or # multipart form content. diff --git a/httpx/_status_codes.py b/httpx/_status_codes.py index e5004412..671c30e1 100644 --- a/httpx/_status_codes.py +++ b/httpx/_status_codes.py @@ -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: diff --git a/httpx/_transports/mock.py b/httpx/_transports/mock.py index 8a70dfe1..1434166d 100644 --- a/httpx/_transports/mock.py +++ b/httpx/_transports/mock.py @@ -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 diff --git a/setup.cfg b/setup.cfg index 27f18be4..3e2a3357 100644 --- 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 diff --git a/tests/test_config.py b/tests/test_config.py index 4056658a..d496cd4a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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(): diff --git a/tests/test_content.py b/tests/test_content.py index 235e63f4..7b13090b 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -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)