Typing: enable warn_return_any (#2477)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Martijn Pieters · committed by GitHub · parent 0eb97fc · Browse files · 8 files·+17 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+17 added−7 removed
- tests:+2 added−2 removed
- other:+15 added−5 removed
Provenance
- Commit
2d37321- Tree
0326ac7- Author
Martijn Pieters <mj@zopatista.com>- Committer
GitHub <noreply@github.com>- Parent
0eb97fc
8 files changed+17 added−7 removed
modified:httpx/_decoders.py+1 added
102 unmodified lines103 ) from None104 105 self.decompressor = brotli.Decompressor()106 self.seen_data = False107+ self._decompress: typing.Callable[[bytes], bytes]108 if hasattr(self.decompressor, "decompress"):109 # The 'brotlicffi' package.110 self._decompress = self.decompressor.decompress # pragma: no cover111 else:223 unmodified linesmodified:httpx/_main.py+3 added-1 removed
98 unmodified lines99 content_type = response.headers.get("Content-Type")100 if content_type is not None:101 mime_type, _, _ = content_type.partition(";")102 try:103+ return typing.cast(103- return pygments.lexers.get_lexer_for_mimetype(mime_type.strip()).name104+ str, pygments.lexers.get_lexer_for_mimetype(mime_type.strip()).name105+ )106 except pygments.util.ClassNotFound: # pragma: no cover107 pass108 return "" # pragma: no cover109 397 unmodified linesmodified:httpx/_models.py+6 added-2 removed
538 unmodified lines539 540 @property541 def http_version(self) -> str:542 try:543- return self.extensions["http_version"].decode("ascii", errors="ignore")543+ http_version: bytes = self.extensions["http_version"]544 except KeyError:545 return "HTTP/1.1"546+ else:547+ return http_version.decode("ascii", errors="ignore")548 549 @property550 def reason_phrase(self) -> str:551 try:550- return self.extensions["reason_phrase"].decode("ascii", errors="ignore")552+ reason_phrase: bytes = self.extensions["reason_phrase"]553 except KeyError:554 return codes.get_reason_phrase(self.status_code)555+ else:556+ return reason_phrase.decode("ascii", errors="ignore")557 558 @property559 def url(self) -> URL:560 """649 unmodified linesmodified:httpx/_urls.py+3 added-1 removed
68 unmodified lines69 * `url.query` is raw bytes, without URL escaping. A URL query string portion can only70 be properly URL escaped when decoding the parameter names and values themselves.71 """72 73+ _uri_reference: rfc3986.URIReference74+75 def __init__(76 self, url: typing.Union["URL", str] = "", **kwargs: typing.Any77 ) -> None:78 if isinstance(url, str):429 unmodified lines508 def __eq__(self, other: typing.Any) -> bool:509 return isinstance(other, (URL, str)) and str(self) == str(URL(other))510 511 def __str__(self) -> str:510- return self._uri_reference.unsplit()512+ return typing.cast(str, self._uri_reference.unsplit())513 514 def __repr__(self) -> str:515 class_name = self.__class__.__name__516 url_str = str(self)237 unmodified linesmodified:httpx/_utils.py+1 added-1 removed
399 unmodified lines400 return trio.current_time()401 elif library == "curio": # pragma: no cover402 import curio403 404- return await curio.clock()404+ return typing.cast(float, await curio.clock())405 406 import asyncio407 408 return asyncio.get_event_loop().time()123 unmodified linesmodified:tests/conftest.py+1 added-1 removed
50 unmodified lines51 async def my_async_test():52 ...53 ```54 """55- return request.param55+ return typing.cast(str, request.param)56 57 58 @pytest.fixture(scope="function", autouse=True)59 def clean_environ():264 unmodified linesmodified:tests/test_content.py+1 added-1 removed
61 unmodified lines62 63 @pytest.mark.asyncio64 async def test_async_bytesio_content():65 class AsyncBytesIO:66- def __init__(self, content):66+ def __init__(self, content: bytes):67 self._idx = 068 self._content = content69 70 async def aread(self, chunk_size: int) -> bytes:380 unmodified linesmodified:setup.cfg+1 added
14 unmodified lines15 disallow_untyped_decorators = True16 warn_redundant_casts = True17 strict_concatenate = True18 disallow_incomplete_defs = True19+warn_return_any = True20 21 [mypy-tests.*]22 disallow_untyped_defs = False23 check_untyped_defs = True17 unmodified lines