-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from gunyu1019/feature/2-annotated
[Feat] Support Annotated
- Loading branch information
Showing
20 changed files
with
279 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from collections.abc import Collection | ||
from types import UnionType, GenericAlias | ||
from typing import Annotated, get_origin | ||
|
||
|
||
def is_subclass_safe(_class, _class_info) -> bool: | ||
""" | ||
Same functionality as `issubclass` method | ||
However, _class parameter can be list of type. | ||
""" | ||
_class = make_collection(_class) | ||
return any([issubclass(t, _class_info) for t in _class if isinstance(t, type)]) | ||
|
||
|
||
def separate_union_type(t): | ||
""" | ||
If type is Union, return list of type | ||
else return t | ||
""" | ||
if isinstance(t, UnionType): | ||
return t.__args__ | ||
return t | ||
|
||
|
||
def is_annotated_parameter(t) -> bool: | ||
""" | ||
Return `True` if type is Annotated | ||
""" | ||
return get_origin(t) is Annotated | ||
|
||
|
||
def get_origin_for_generic(t): | ||
""" | ||
If type is Generic, return origin of generic type | ||
else return t | ||
""" | ||
if isinstance(t, GenericAlias): | ||
return t.__origin__ | ||
return t | ||
|
||
|
||
def make_collection(t): | ||
if not isinstance(t, Collection): | ||
return (t,) | ||
return t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import asyncio | ||
import aiohttp | ||
|
||
from async_client import request, Session, Query | ||
from typing import Annotated | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
|
||
class BusAPI(Session): | ||
def __init__(self, loop: asyncio.AbstractEventLoop): | ||
super().__init__("https://api.yhs.kr", loop) | ||
|
||
@request("GET", "/bus/station") | ||
async def station_search_with_query( | ||
self, response: aiohttp.ClientResponse, name: Annotated[str, Query] | ||
): | ||
return await response.json() | ||
|
||
|
||
async def main(): | ||
async with BusAPI(loop) as client: | ||
response = await client.station_search_with_query(name="bus-station-name") | ||
data = await response.json() | ||
print(len) | ||
|
||
|
||
loop.run_until_complete(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.