mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-23 11:39:17 +08:00
Add type hint to provide autocompletion for Request class instances. (#1642)
This commit is contained in:
parent
0f44cf8012
commit
3026b8f597
@ -13,7 +13,7 @@ import warnings
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, NewType, Type
|
from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, NewType, Type
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import analytics
|
import analytics
|
||||||
@ -424,7 +424,7 @@ class Request:
|
|||||||
# Create request
|
# Create request
|
||||||
self._request = self._create_request(method, url, **kwargs)
|
self._request = self._create_request(method, url, **kwargs)
|
||||||
|
|
||||||
def __await__(self):
|
def __await__(self) -> Generator[None, Any, "Request"]:
|
||||||
"""
|
"""
|
||||||
Wrap Request's __await__ magic function to create request calls which are executed in one line.
|
Wrap Request's __await__ magic function to create request calls which are executed in one line.
|
||||||
"""
|
"""
|
||||||
|
@ -200,7 +200,7 @@ async def client():
|
|||||||
class TestRequest:
|
class TestRequest:
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_get(self):
|
async def test_get(self):
|
||||||
client_response: Request = await Request(
|
client_response = await Request(
|
||||||
method=Request.Method.GET,
|
method=Request.Method.GET,
|
||||||
url="http://headers.jsontest.com/",
|
url="http://headers.jsontest.com/",
|
||||||
)
|
)
|
||||||
@ -210,7 +210,7 @@ class TestRequest:
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_post(self):
|
async def test_post(self):
|
||||||
client_response: Request = await Request(
|
client_response = await Request(
|
||||||
method=Request.Method.POST,
|
method=Request.Method.POST,
|
||||||
url="https://reqres.in/api/users",
|
url="https://reqres.in/api/users",
|
||||||
json={"name": "morpheus", "job": "leader"},
|
json={"name": "morpheus", "job": "leader"},
|
||||||
@ -228,7 +228,7 @@ class TestRequest:
|
|||||||
id: str
|
id: str
|
||||||
createdAt: str
|
createdAt: str
|
||||||
|
|
||||||
client_response: Request = await Request(
|
client_response = await Request(
|
||||||
method=Request.Method.POST,
|
method=Request.Method.POST,
|
||||||
url="https://reqres.in/api/users",
|
url="https://reqres.in/api/users",
|
||||||
json={"name": "morpheus", "job": "leader"},
|
json={"name": "morpheus", "job": "leader"},
|
||||||
@ -242,7 +242,7 @@ class TestRequest:
|
|||||||
name: Literal[str] = "John"
|
name: Literal[str] = "John"
|
||||||
job: str
|
job: str
|
||||||
|
|
||||||
client_response: Request = await Request(
|
client_response = await Request(
|
||||||
method=Request.Method.POST,
|
method=Request.Method.POST,
|
||||||
url="https://reqres.in/api/users",
|
url="https://reqres.in/api/users",
|
||||||
json={"name": "morpheus", "job": "leader"},
|
json={"name": "morpheus", "job": "leader"},
|
||||||
@ -261,7 +261,7 @@ class TestRequest:
|
|||||||
|
|
||||||
validate_response_data.side_effect = Exception()
|
validate_response_data.side_effect = Exception()
|
||||||
|
|
||||||
client_response: Request = await Request(
|
client_response = await Request(
|
||||||
method=Request.Method.GET,
|
method=Request.Method.GET,
|
||||||
url="https://reqres.in/api/users",
|
url="https://reqres.in/api/users",
|
||||||
exception_type=ResponseValidationException,
|
exception_type=ResponseValidationException,
|
||||||
@ -275,7 +275,7 @@ class TestRequest:
|
|||||||
return response
|
return response
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
client_response: Request = await Request(
|
client_response = await Request(
|
||||||
method=Request.Method.POST,
|
method=Request.Method.POST,
|
||||||
url="https://reqres.in/api/users",
|
url="https://reqres.in/api/users",
|
||||||
json={"name": "morpheus", "job": "leader"},
|
json={"name": "morpheus", "job": "leader"},
|
||||||
@ -294,7 +294,7 @@ class TestRequest:
|
|||||||
return response
|
return response
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
client_response: Request = await Request(
|
client_response = await Request(
|
||||||
method=Request.Method.POST,
|
method=Request.Method.POST,
|
||||||
url="https://reqres.in/api/users",
|
url="https://reqres.in/api/users",
|
||||||
json={"name": "morpheus", "job": "leader"},
|
json={"name": "morpheus", "job": "leader"},
|
||||||
|
Loading…
Reference in New Issue
Block a user