Remove and dissallow unused type ignores (#2470)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Remove and dissallow unused type ignores * add pragmas * fix ignore
authored by Adrian Garcia Badaracco · committed by GitHub · parent 1fc6a52 · Browse files · 7 files·+28 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+28 added−24 removed
- tests:+14 added−13 removed
- other:+14 added−11 removed
Provenance
- Commit
69e13cb- Tree
9d82162- Author
Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
1fc6a52
7 files changed+28 added−24 removed
modified:httpx/_transports/mock.py+1 added-1 removed
27 unmodified lines28 # return the result.29 30 # https://simonwillison.net/2020/Sep/2/await-me-maybe/31 if asyncio.iscoroutine(response):32- response = await response # type: ignore[func-returns-value,assignment]32+ response = await response33 34 return responsemodified:httpx/_config.py+9 added-7 removed
1 import os2 import ssl3+import sys4 import typing5 from pathlib import Path6 7 import certifi117 unmodified lines125 context.check_hostname = True126 127 # Signal to server support for PHA in TLS 1.3. Raises an128 # AttributeError if only read-only access is implemented.129+ if sys.version_info >= (3, 8): # pragma: no cover128- try:129- context.post_handshake_auth = True # type: ignore130- except AttributeError: # pragma: no cover131- pass130+ try:131+ context.post_handshake_auth = True132+ except AttributeError: # pragma: no cover133+ pass134 135 # Disable using 'commonName' for SSLContext.check_hostname136 # when the 'subjectAltName' extension isn't available.137 try:136- context.hostname_checks_common_name = False # type: ignore138+ context.hostname_checks_common_name = False139 except AttributeError: # pragma: no cover140 pass141 142 if ca_bundle_path.is_file():20 unmodified lines163 if ssl.HAS_ALPN:164 alpn_idents = ["http/1.1", "h2"] if self.http2 else ["http/1.1"]165 context.set_alpn_protocols(alpn_idents)166 165- if hasattr(context, "keylog_filename"): # pragma: no cover (Available in 3.8+)167+ if sys.version_info >= (3, 8): # pragma: no cover168 keylogfile = os.environ.get("SSLKEYLOGFILE")169 if keylogfile and self.trust_env:168- context.keylog_filename = keylogfile # type: ignore170+ context.keylog_filename = keylogfile171 172 return context173 174 def _load_client_certs(self, ssl_context: ssl.SSLContext) -> None:191 unmodified linesmodified:httpx/_content.py+1 added-1 removed
187 unmodified lines188 """189 Handles encoding the given `content`, `data`, `files`, and `json`,190 returning a two-tuple of (<headers>, <stream>).191 """192- if data is not None and not isinstance(data, Mapping): # type: ignore192+ if data is not None and not isinstance(data, Mapping):193 # We prefer to separate `content=<bytes|str|byte iterator|bytes aiterator>`194 # for raw request content, and `data=<form data>` for url encoded or195 # multipart form content.196 #39 unmodified linesmodified:httpx/_status_codes.py+2 added-2 removed
20 unmodified lines21 * RFC 8470: Using Early Data in HTTP22 """23 24 def __new__(cls, value: int, phrase: str = "") -> "codes":25- obj = int.__new__(cls, value) # type: ignore25+ obj = int.__new__(cls, value)26 obj._value_ = value27 28- obj.phrase = phrase # type: ignore28+ obj.phrase = phrase # type: ignore[attr-defined]29 return obj30 31 def __str__(self) -> str:32 return str(self.value)126 unmodified linesmodified:tests/test_config.py+12 added-11 removed
176 unmodified lines177 reason="requires OpenSSL 1.1.1 or higher",178 )179 @pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")180 def test_ssl_config_support_for_keylog_file(tmpdir, monkeypatch): # pragma: no cover181+ if sys.version_info > (3, 8):181- with monkeypatch.context() as m:182- m.delenv("SSLKEYLOGFILE", raising=False)182+ with monkeypatch.context() as m:183+ m.delenv("SSLKEYLOGFILE", raising=False)184 184- context = httpx.create_ssl_context(trust_env=True)185+ context = httpx.create_ssl_context(trust_env=True)186 186- assert context.keylog_filename is None # type: ignore187+ assert context.keylog_filename is None188 188- filename = str(tmpdir.join("test.log"))189+ filename = str(tmpdir.join("test.log"))190 190- with monkeypatch.context() as m:191- m.setenv("SSLKEYLOGFILE", filename)191+ with monkeypatch.context() as m:192+ m.setenv("SSLKEYLOGFILE", filename)193 193- context = httpx.create_ssl_context(trust_env=True)194+ context = httpx.create_ssl_context(trust_env=True)195 195- assert context.keylog_filename == filename # type: ignore196+ assert context.keylog_filename == filename197 197- context = httpx.create_ssl_context(trust_env=False)198+ context = httpx.create_ssl_context(trust_env=False)199 199- assert context.keylog_filename is None # type: ignore200+ assert context.keylog_filename is None201 202 203 def test_proxy_from_url():204 proxy = httpx.Proxy("https://example.com")19 unmodified linesmodified:tests/test_content.py+2 added-2 removed
103 unmodified lines104 [part for part in stream]105 106 # Support 'data' for compat with requests.107 with pytest.warns(DeprecationWarning):108- headers, stream = encode_request(data=hello_world()) # type: ignore108+ headers, stream = encode_request(data=hello_world())109 assert isinstance(stream, typing.Iterable)110 assert not isinstance(stream, typing.AsyncIterable)111 112 content = b"".join([part for part in stream])21 unmodified lines134 [part async for part in stream]135 136 # Support 'data' for compat with requests.137 with pytest.warns(DeprecationWarning):138- headers, stream = encode_request(data=hello_world()) # type: ignore138+ headers, stream = encode_request(data=hello_world())139 assert not isinstance(stream, typing.Iterable)140 assert isinstance(stream, typing.AsyncIterable)141 142 content = b"".join([part async for part in stream])308 unmodified linesmodified:setup.cfg+1 added
6 unmodified lines7 disallow_any_generics = True8 ignore_missing_imports = True9 no_implicit_optional = True10 show_error_codes = True11+warn_unused_ignores = True12 warn_unused_configs = True13 disallow_subclassing_any = True14 check_untyped_defs = True15 disallow_untyped_decorators = True23 unmodified lines