Remove and dissallow unused type ignores (#2470)

* Remove and dissallow unused type ignores

* add pragmas

* fix ignore
This commit is contained in:
Adrian Garcia Badaracco 2022-11-29 10:55:45 -06:00 committed by GitHub
parent 1fc6a52546
commit 69e13cbc39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 24 deletions

View 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

View 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.

View 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:

View 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

View File

@ -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

View 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():

View 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)