Skip to content

Commit

Permalink
Rename JSON -> Json
Browse files Browse the repository at this point in the history
  • Loading branch information
unmade committed Mar 9, 2020
1 parent 2b8e2fd commit 42c958a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/apiwrappers/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any, MutableMapping, Union, cast

from apiwrappers.structures import CaseInsensitiveDict, Url
from apiwrappers.typedefs import JSON, Auth, Data, Files, QueryParams
from apiwrappers.typedefs import Auth, Data, Files, Json, QueryParams


class Method(enum.Enum):
Expand Down Expand Up @@ -94,7 +94,7 @@ class Request:
auth: Auth = None
data: Data = None
files: Files = None
json: JSON = None
json: Json = None

def __init__(
self,
Expand All @@ -106,7 +106,7 @@ def __init__(
auth: Auth = None,
data: Data = None,
files: Files = None,
json: JSON = None,
json: Json = None,
):
# pylint: disable=redefined-outer-name,too-many-arguments
if sum((data is not None, files is not None, json is not None)) > 1:
Expand Down Expand Up @@ -164,11 +164,11 @@ def text(self) -> str:
"""
return self.content.decode(self.encoding)

def json(self) -> JSON:
def json(self) -> Json:
"""
Returns the json-encoded content of the response.
Raises:
ValueError: if the response body does not contain valid json.
"""
return cast(JSON, json.loads(self.content.decode(self.encoding)))
return cast(Json, json.loads(self.content.decode(self.encoding)))
2 changes: 1 addition & 1 deletion src/apiwrappers/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Data = Union[str, None, Mapping[str, Any], Iterable[Tuple[str, Any]]]
FilesValue = Union[BinaryIO, Tuple[str, BinaryIO], Tuple[str, BinaryIO, str]]
Files = Optional[Dict[str, FilesValue]]
JSON = Union[str, int, float, bool, None, Mapping[str, Any], List[Any]]
Json = Union[str, int, float, bool, None, Mapping[str, Any], List[Any]]
QueryParams = Mapping[str, Optional[Iterable[str]]]
Timeout = Union[int, float, None]
Verify = Union[bool, str]
12 changes: 6 additions & 6 deletions src/apiwrappers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get_type_hints,
)

from apiwrappers.typedefs import JSON
from apiwrappers.typedefs import Json

T = TypeVar("T")

Expand All @@ -24,7 +24,7 @@ def build_url(host: str, path: str) -> str:
return urllib.parse.urlunsplit((scheme, netloc, path, query, fragment))


def getitem(data: JSON, key: Optional[str]) -> JSON:
def getitem(data: Json, key: Optional[str]) -> Json:
if not key:
return data
parts = key.split(".")
Expand All @@ -38,7 +38,7 @@ def getitem(data: JSON, key: Optional[str]) -> JSON:
return data


def fromjson(objtype: Union[Callable[..., T], Type[T]], data: JSON) -> T:
def fromjson(objtype: Union[Callable[..., T], Type[T]], data: Json) -> T:
if objtype is Any:
obj = data
elif dataclasses.is_dataclass(objtype):
Expand All @@ -60,7 +60,7 @@ def _is_generic_type(obj: Any) -> bool:
return hasattr(obj, "__origin__") and hasattr(obj, "__args__")


def _handle_dataclass(objtype: Any, data: JSON) -> Any:
def _handle_dataclass(objtype: Any, data: Json) -> Any:
if not isinstance(data, Mapping):
raise ValueError(f"Expected `Mapping`, got: {type(data)}")
kwargs = {}
Expand All @@ -79,7 +79,7 @@ def _handle_dataclass(objtype: Any, data: JSON) -> Any:
return objtype(**kwargs)


def _handle_namedtuple(objtype: Any, data: JSON) -> Any:
def _handle_namedtuple(objtype: Any, data: Json) -> Any:
hints = get_type_hints(objtype)
field_defaults = objtype._field_defaults # pylint: disable=protected-access
if isinstance(data, list):
Expand All @@ -97,7 +97,7 @@ def _handle_namedtuple(objtype: Any, data: JSON) -> Any:
raise ValueError(f"Expected `List` or `Mapping`, got: {type(data)}")


def _handle_generic_type(objtype: Any, data: JSON) -> Any:
def _handle_generic_type(objtype: Any, data: Json) -> Any:
origin = objtype.__origin__
args = objtype.__args__
if origin in (list, set, tuple):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_drivers/httpbin_client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Awaitable, Generic, MutableMapping, Optional, TypeVar, overload

from apiwrappers import AsyncDriver, Driver, Response, Url
from apiwrappers.typedefs import JSON, Data, Files, QueryParams, Timeout
from apiwrappers.typedefs import Data, Files, Json, QueryParams, Timeout

T = TypeVar("T", Driver, AsyncDriver)

Expand All @@ -22,14 +22,14 @@ class HttpBin(Generic[T]):
self: HttpBin[Driver],
data: Optional[Data] = None,
files: Optional[Files] = None,
json: Optional[JSON] = None,
json: Optional[Json] = None,
) -> Response: ...
@overload
def post(
self: HttpBin[AsyncDriver],
data: Optional[Data] = None,
files: Optional[Files] = None,
json: Optional[JSON] = None,
json: Optional[Json] = None,
) -> Awaitable[Response]: ...
@overload
def headers(
Expand Down

0 comments on commit 42c958a

Please sign in to comment.