Skip to content

Commit

Permalink
Bump mypy from 1.6.1 to 1.7.0 (aio-libs#7833)
Browse files Browse the repository at this point in the history
Bumps [mypy](https://github.com/python/mypy) from 1.6.1 to 1.7.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/python/mypy/blob/master/CHANGELOG.md">mypy's
changelog</a>.</em></p>
<blockquote>
<h1>Mypy Release Notes</h1>
<h2>Next release</h2>
<p>Stubgen will now include <code>__all__</code> in its output if it is
in the input file (PR <a
href="https://redirect.github.com/python/mypy/pull/16356">16356</a>).</p>
<h2>Mypy 1.7</h2>
<p>We’ve just uploaded mypy 1.7 to the Python Package Index (<a
href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type
checker for Python. This release includes new features, performance
improvements and bug fixes. You can install it as follows:</p>
<pre><code>python3 -m pip install -U mypy
</code></pre>
<p>You can read the full documentation for this release on <a
href="http://mypy.readthedocs.io">Read the Docs</a>.</p>
<h4>Using TypedDict for <code>**kwargs</code> Typing</h4>
<p>Mypy now has support for using <code>Unpack[...]</code> with a
TypedDict type to annotate <code>**kwargs</code> arguments enabled by
default. Example:</p>
<pre><code># Or 'from typing_extensions import ...'
from typing import TypedDict, Unpack
<p>class Person(TypedDict):
name: str
age: int</p>
<p>def foo(**kwargs: Unpack[Person]) -&gt; None:
...</p>
<p>foo(name=&quot;x&quot;, age=1)  # Ok
foo(name=1)  # Error
</code></pre></p>
<p>The definition of <code>foo</code> above is equivalent to the one
below, with keyword-only arguments <code>name</code> and
<code>age</code>:</p>
<pre><code>def foo(*, name: str, age: int) -&gt; None:
    ...
</code></pre>
<p>Refer to <a href="https://peps.python.org/pep-0692/">PEP 692</a> for
more information. Note that unlike in the current version of the PEP,
mypy always treats signatures with <code>Unpack[SomeTypedDict]</code> as
equivalent to their expanded forms with explicit keyword arguments, and
there aren't special type checking rules for TypedDict arguments.</p>
<p>This was contributed by Ivan Levkivskyi back in 2022 (PR <a
href="https://redirect.github.com/python/mypy/pull/13471">13471</a>).</p>
<h4>TypeVarTuple Support Enabled (Experimental)</h4>
<p>Mypy now has support for variadic generics (TypeVarTuple) enabled by
default, as an experimental feature. Refer to <a
href="https://peps.python.org/pep-0646/">PEP 646</a> for the
details.</p>
<p>TypeVarTuple was implemented by Jared Hance and Ivan Levkivskyi over
several mypy releases, with help from Jukka Lehtosalo.</p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/python/mypy/commit/f6b9972329d5d68f6defc92a10cc4c3bc339c27b"><code>f6b9972</code></a>
Remove +dev from version</li>
<li><a
href="https://github.com/python/mypy/commit/62bcae2d9bad12c5d3b5dda23dc031e1c7ddf136"><code>62bcae2</code></a>
Fix handling of tuple type context with unpacks (<a
href="https://redirect.github.com/python/mypy/issues/16444">#16444</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/c22294a80b000ea673e407994ac5111644944486"><code>c22294a</code></a>
Handle TypeVarTupleType when checking overload constraints (<a
href="https://redirect.github.com/python/mypy/issues/16428">#16428</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/8813968abb657113df5edfa207db46b0649c9dce"><code>8813968</code></a>
Fix type narrowing in lambda expressions (<a
href="https://redirect.github.com/python/mypy/issues/16407">#16407</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/681e54cfe1642adddc41c4ff11198b8bc955d5af"><code>681e54c</code></a>
Fix crash on unpack call special-casing (<a
href="https://redirect.github.com/python/mypy/issues/16381">#16381</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/f68f46351e30644aefd19900ba1634595adc1d09"><code>f68f463</code></a>
Fix file reloading in dmypy with --export-types (<a
href="https://redirect.github.com/python/mypy/issues/16359">#16359</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/5624f401b3786ebdbe167c27297ed778cce3faa5"><code>5624f40</code></a>
Fix daemon crash caused by deleted submodule (<a
href="https://redirect.github.com/python/mypy/issues/16370">#16370</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/ad0e183b0df7cc3dd94d9e1cd6f5710859beda96"><code>ad0e183</code></a>
Enable Unpack/TypeVarTuple support (<a
href="https://redirect.github.com/python/mypy/issues/16354">#16354</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/b064a5c183b53a84d895bb8e3c36a3a74e24be9c"><code>b064a5c</code></a>
Fix dmypy inspect on Windows (<a
href="https://redirect.github.com/python/mypy/issues/16355">#16355</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/4e30e896486b774cdecaef6d3521a585b8acf8bc"><code>4e30e89</code></a>
Fix dmypy inspect for namespace packages (<a
href="https://redirect.github.com/python/mypy/issues/16357">#16357</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/python/mypy/compare/v1.6.1...v1.7.0">compare
view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=mypy&package-manager=pip&previous-version=1.6.1&new-version=1.7.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)

</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sam Bull <git@sambull.org>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and Xiang Li committed Dec 4, 2023
1 parent 4ac9f33 commit 442289d
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 50 deletions.
4 changes: 2 additions & 2 deletions aiohttp/client_reqrep.py
Expand Up @@ -462,7 +462,7 @@ def update_cookies(self, cookies: Optional[LooseCookies]) -> None:
if not cookies:
return

c: SimpleCookie[str] = SimpleCookie()
c = SimpleCookie()
if hdrs.COOKIE in self.headers:
c.load(self.headers.get(hdrs.COOKIE, ""))
del self.headers[hdrs.COOKIE]
Expand Down Expand Up @@ -789,7 +789,7 @@ def __init__(
assert isinstance(url, URL)

self.method = method
self.cookies: SimpleCookie[str] = SimpleCookie()
self.cookies = SimpleCookie()

self._real_url = url
self._url = url.with_fragment(None)
Expand Down
10 changes: 4 additions & 6 deletions aiohttp/cookiejar.py
Expand Up @@ -65,7 +65,7 @@ def __init__(
loop: Optional[asyncio.AbstractEventLoop] = None,
) -> None:
super().__init__(loop=loop)
self._cookies: DefaultDict[Tuple[str, str], SimpleCookie[str]] = defaultdict(
self._cookies: DefaultDict[Tuple[str, str], SimpleCookie] = defaultdict(
SimpleCookie
)
self._host_only_cookies: Set[Tuple[str, str]] = set()
Expand Down Expand Up @@ -168,7 +168,7 @@ def update_cookies(self, cookies: LooseCookies, response_url: URL = URL()) -> No

for name, cookie in cookies:
if not isinstance(cookie, Morsel):
tmp: SimpleCookie[str] = SimpleCookie()
tmp = SimpleCookie()
tmp[name] = cookie # type: ignore[assignment]
cookie = tmp[name]

Expand Down Expand Up @@ -232,11 +232,9 @@ def update_cookies(self, cookies: LooseCookies, response_url: URL = URL()) -> No

self._do_expiration()

def filter_cookies(
self, request_url: URL = URL()
) -> Union["BaseCookie[str]", "SimpleCookie[str]"]:
def filter_cookies(self, request_url: URL = URL()) -> "BaseCookie[str]":
"""Returns this jar's cookies filtered by their attributes."""
filtered: Union["SimpleCookie[str]", "BaseCookie[str]"] = (
filtered: Union[SimpleCookie, "BaseCookie[str]"] = (
SimpleCookie() if self._quote_cookie else BaseCookie()
)
if not self._cookies:
Expand Down
147 changes: 109 additions & 38 deletions aiohttp/web_response.py
Expand Up @@ -8,6 +8,7 @@
import warnings
from concurrent.futures import Executor
from http import HTTPStatus
from http.cookies import SimpleCookie
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -27,12 +28,10 @@
from .helpers import (
ETAG_ANY,
QUOTED_ETAG_RE,
CookieMixin,
ETag,
HeadersMixin,
must_be_empty_body,
parse_http_date,
populate_with_cookies,
rfc822_formatted_time,
sentinel,
should_remove_content_length,
Expand All @@ -45,7 +44,7 @@
__all__ = ("ContentCoding", "StreamResponse", "Response", "json_response")


if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from .web_request import BaseRequest

BaseClass = MutableMapping[str, Any]
Expand All @@ -68,26 +67,9 @@ class ContentCoding(enum.Enum):
############################################################


class StreamResponse(BaseClass, HeadersMixin, CookieMixin):
__slots__ = (
"_length_check",
"_body",
"_keep_alive",
"_chunked",
"_compression",
"_compression_force",
"_req",
"_payload_writer",
"_eof_sent",
"_must_be_empty_body",
"_body_length",
"_state",
"_headers",
"_status",
"_reason",
"_cookies",
"__weakref__",
)
class StreamResponse(BaseClass, HeadersMixin):

_length_check = True

def __init__(
self,
Expand All @@ -96,13 +78,12 @@ def __init__(
reason: Optional[str] = None,
headers: Optional[LooseHeaders] = None,
) -> None:
super().__init__()
self._length_check = True
self._body = None
self._keep_alive: Optional[bool] = None
self._chunked = False
self._compression = False
self._compression_force: Optional[ContentCoding] = None
self._cookies = SimpleCookie()

self._req: Optional[BaseRequest] = None
self._payload_writer: Optional[AbstractStreamWriter] = None
Expand Down Expand Up @@ -172,25 +153,118 @@ def force_close(self) -> None:
def body_length(self) -> int:
return self._body_length

def enable_chunked_encoding(self) -> None:
@property
def output_length(self) -> int:
warnings.warn("output_length is deprecated", DeprecationWarning)
assert self._payload_writer
return self._payload_writer.buffer_size

def enable_chunked_encoding(self, chunk_size: Optional[int] = None) -> None:
"""Enables automatic chunked transfer encoding."""
self._chunked = True

if hdrs.CONTENT_LENGTH in self._headers:
raise RuntimeError(
"You can't enable chunked encoding when " "a content length is set"
)
if chunk_size is not None:
warnings.warn("Chunk size is deprecated #1615", DeprecationWarning)

def enable_compression(self, force: Optional[ContentCoding] = None) -> None:
def enable_compression(
self, force: Optional[Union[bool, ContentCoding]] = None
) -> None:
"""Enables response compression encoding."""
# Backwards compatibility for when force was a bool <0.17.
if type(force) == bool:
force = ContentCoding.deflate if force else ContentCoding.identity
warnings.warn(
"Using boolean for force is deprecated #3318", DeprecationWarning
)
elif force is not None:
assert isinstance(force, ContentCoding), (
"force should one of " "None, bool or " "ContentEncoding"
)

self._compression = True
self._compression_force = force

@property
def headers(self) -> "CIMultiDict[str]":
return self._headers

@property
def cookies(self) -> SimpleCookie:
return self._cookies

def set_cookie(
self,
name: str,
value: str,
*,
expires: Optional[str] = None,
domain: Optional[str] = None,
max_age: Optional[Union[int, str]] = None,
path: str = "/",
secure: Optional[bool] = None,
httponly: Optional[bool] = None,
version: Optional[str] = None,
samesite: Optional[str] = None,
) -> None:
"""Set or update response cookie.
Sets new cookie or updates existent with new value.
Also updates only those params which are not None.
"""
old = self._cookies.get(name)
if old is not None and old.coded_value == "":
# deleted cookie
self._cookies.pop(name, None)

self._cookies[name] = value
c = self._cookies[name]

if expires is not None:
c["expires"] = expires
elif c.get("expires") == "Thu, 01 Jan 1970 00:00:00 GMT":
del c["expires"]

if domain is not None:
c["domain"] = domain

if max_age is not None:
c["max-age"] = str(max_age)
elif "max-age" in c:
del c["max-age"]

c["path"] = path

if secure is not None:
c["secure"] = secure
if httponly is not None:
c["httponly"] = httponly
if version is not None:
c["version"] = version
if samesite is not None:
c["samesite"] = samesite

def del_cookie(
self, name: str, *, domain: Optional[str] = None, path: str = "/"
) -> None:
"""Delete cookie.
Creates new empty expired cookie.
"""
# TODO: do we need domain/path here?
self._cookies.pop(name, None)
self.set_cookie(
name,
"",
max_age=0,
expires="Thu, 01 Jan 1970 00:00:00 GMT",
domain=domain,
path=path,
)

@property
def content_length(self) -> Optional[int]:
# Just a placeholder for adding setter
Expand Down Expand Up @@ -291,7 +365,7 @@ def etag(self, value: Optional[Union[ETag, str]]) -> None:
elif isinstance(value, str):
validate_etag_value(value)
self._headers[hdrs.ETAG] = f'"{value}"'
elif isinstance(value, ETag) and isinstance(value.value, str): # type: ignore[redundant-expr]
elif isinstance(value, ETag) and isinstance(value.value, str):
validate_etag_value(value.value)
hdr_value = f'W/"{value.value}"' if value.is_weak else f'"{value.value}"'
self._headers[hdrs.ETAG] = hdr_value
Expand Down Expand Up @@ -363,7 +437,9 @@ async def _prepare_headers(self) -> None:
version = request.version

headers = self._headers
populate_with_cookies(headers, self.cookies)
for cookie in self._cookies.values():
value = cookie.output(header="")[1:]
headers.add(hdrs.SET_COOKIE, value)

if self._compression:
await self._start_compression(request)
Expand Down Expand Up @@ -497,13 +573,6 @@ def __eq__(self, other: object) -> bool:


class Response(StreamResponse):
__slots__ = (
"_body_payload",
"_compressed_body",
"_zlib_executor_size",
"_zlib_executor",
)

def __init__(
self,
*,
Expand Down Expand Up @@ -602,7 +671,7 @@ def body(self, body: bytes) -> None:

# copy payload headers
if body.headers:
for key, value in body.headers.items():
for (key, value) in body.headers.items():
if key not in headers:
headers[key] = value

Expand All @@ -616,7 +685,9 @@ def text(self) -> Optional[str]:

@text.setter
def text(self, text: str) -> None:
assert isinstance(text, str), "text argument must be str (%r)" % type(text)
assert text is None or isinstance(
text, str
), "text argument must be str (%r)" % type(text)

if self.content_type == "application/octet-stream":
self.content_type = "text/plain"
Expand Down
2 changes: 1 addition & 1 deletion requirements/constraints.txt
Expand Up @@ -108,7 +108,7 @@ multidict==6.0.4
# -r requirements/multidict.in
# -r requirements/runtime-deps.in
# yarl
mypy==1.6.1 ; implementation_name == "cpython"
mypy==1.7.0 ; implementation_name == "cpython"
# via
# -r requirements/lint.in
# -r requirements/test.in
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Expand Up @@ -103,7 +103,7 @@ multidict==6.0.4
# via
# -r requirements/runtime-deps.in
# yarl
mypy==1.6.1 ; implementation_name == "cpython"
mypy==1.7.0 ; implementation_name == "cpython"
# via
# -r requirements/lint.in
# -r requirements/test.in
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.txt
Expand Up @@ -22,7 +22,7 @@ identify==2.5.26
# via pre-commit
iniconfig==2.0.0
# via pytest
mypy==1.6.1 ; implementation_name == "cpython"
mypy==1.7.0 ; implementation_name == "cpython"
# via -r requirements/lint.in
mypy-extensions==1.0.0
# via mypy
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Expand Up @@ -53,7 +53,7 @@ multidict==6.0.4
# via
# -r requirements/runtime-deps.in
# yarl
mypy==1.6.1 ; implementation_name == "cpython"
mypy==1.7.0 ; implementation_name == "cpython"
# via -r requirements/test.in
mypy-extensions==1.0.0
# via mypy
Expand Down

0 comments on commit 442289d

Please sign in to comment.