Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Trylesinski authored and Kludex committed Dec 17, 2021
1 parent 0eebb70 commit 9348fb2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@
import os
import re

from setuptools import find_packages, setup
from setuptools import setup, find_packages


def get_version(package):
Expand Down
81 changes: 43 additions & 38 deletions starlette/testclient.py
Expand Up @@ -234,6 +234,8 @@ def handle_request(self, request: httpx.Request) -> httpx.Response:
for key, value in request.headers.items()
]

scope: Dict[str, Any]

if scheme in {"ws", "wss"}:
subprotocol = request.headers.get("sec-websocket-protocol", None)
if subprotocol is None:
Expand Down Expand Up @@ -355,8 +357,8 @@ async def send(message: ASGISendEvent) -> None:

response = httpx.Response(**raw_kwargs, request=request)
if template is not None:
response.template = template
response.context = context
response.template = template # type: ignore[attr-defined]
response.context = context # type: ignore[attr-defined]
return response


Expand Down Expand Up @@ -408,42 +410,45 @@ def _portal_factory(self) -> Generator[anyio.abc.BlockingPortal, None, None]:
with anyio.start_blocking_portal(**self.async_backend) as portal:
yield portal

# def request(
# self,
# method: str,
# url: httpx._types.URLTypes,
# *,
# content: httpx._types.RequestContent = None,
# data: httpx._types.RequestData = None,
# files: httpx._types.RequestFiles = None,
# json: Any = None,
# params: httpx._types.QueryParamTypes = None,
# headers: httpx._types.HeaderTypes = None,
# cookies: httpx._types.CookieTypes = None,
# auth: Union[httpx._types.AuthTypes, httpx._client.UseClientDefault] = ...,
# follow_redirects: Union[bool, httpx._client.UseClientDefault] = ...,
# timeout: Union[
# httpx._client.TimeoutTypes, httpx._client.UseClientDefault
# ] = ...,
# extensions: dict = None,
# ) -> httpx.Response:
# # NOTE: This is not necessary.
# url = self.base_url.join(url)
# return super().request(
# method,
# url,
# content=content,
# data=data,
# files=files,
# json=json,
# params=params,
# headers=headers,
# cookies=cookies,
# auth=auth,
# follow_redirects=follow_redirects,
# timeout=timeout,
# extensions=extensions,
# )
def request(
self,
method: str,
url: httpx._types.URLTypes,
*,
content: httpx._types.RequestContent = None,
data: httpx._types.RequestData = None,
files: httpx._types.RequestFiles = None,
json: Any = None,
params: httpx._types.QueryParamTypes = None,
headers: httpx._types.HeaderTypes = None,
cookies: httpx._types.CookieTypes = None,
auth: Union[
httpx._types.AuthTypes, httpx._client.UseClientDefault
] = httpx._client.USE_CLIENT_DEFAULT,
follow_redirects: Union[
bool, httpx._client.UseClientDefault
] = httpx._client.USE_CLIENT_DEFAULT,
timeout: Union[
httpx._client.TimeoutTypes, httpx._client.UseClientDefault
] = httpx._client.USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> httpx.Response:
url = self.base_url.join(url)
return super().request(
method,
url,
content=content,
data=data,
files=files,
json=json,
params=params,
headers=headers,
cookies=cookies,
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def websocket_connect(
self, url: str, subprotocols: Sequence[str] = None, **kwargs: Any
Expand Down
2 changes: 1 addition & 1 deletion tests/middleware/test_session.py
Expand Up @@ -112,7 +112,7 @@ def test_session_cookie_subpath(test_client_factory):
second_app.add_middleware(SessionMiddleware, secret_key="example")
app.mount("/second_app", second_app)
client = test_client_factory(app, base_url="http://testserver/second_app")
response = client.post("/second_app/update_session", json={"some": "data"})
response = client.post("second_app/update_session", json={"some": "data"})
cookie = response.headers["set-cookie"]
cookie_path = re.search(r"; path=(\S+);", cookie).groups()[0]
assert cookie_path == "/second_app"
Expand Down

0 comments on commit 9348fb2

Please sign in to comment.