import os
import ssl
+import sys
import typing
from pathlib import Path
# 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
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
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.
"""
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:
# 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
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
)
@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():
# 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)
# 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)