Skip to content

Commit

Permalink
refactor: move converter.py to utils/
Browse files Browse the repository at this point in the history
  • Loading branch information
leandcesar committed Jan 4, 2023
1 parent 991cdff commit 7b6d033
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion wa_me/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from .context import Ctx # NOQA
from .core import errors # NOQA
from .core.client import Client # NOQA
from .core.converter import as_dict, from_dict # NOQA
from .core.errors import * # NOQA
from .core.http import Route, HTTPClient # NOQA
from .utils.converter import as_dict, from_dict # NOQA
from .utils.routine import Routine, routine # NOQA
from .utils.ttl_dict import TTLDict # NOQA

Expand Down
2 changes: 1 addition & 1 deletion wa_me/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .classes import enums, events, messages, responses
from .core.client import Client
from .core.converter import as_dict, from_dict
from .utils.converter import as_dict, from_dict

__all__ = ("Ctx",)

Expand Down
8 changes: 4 additions & 4 deletions wa_me/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests

__all__ = (
"WhatsappException",
"WaMeException",
"ValidationError",
"HTTPException",
"BadRequest",
Expand All @@ -16,15 +16,15 @@
)


class WhatsappException(Exception):
class WaMeException(Exception):
"""Base exception class for wa_me."""


class ValidationError(WhatsappException):
class ValidationError(WaMeException):
"""An Exception that is raised when there is a Validation Error."""


class HTTPException(WhatsappException):
class HTTPException(WaMeException):
"""Exception that's raised when an HTTP request operation fails.
Parameters
Expand Down
12 changes: 2 additions & 10 deletions wa_me/core/converter.py → wa_me/utils/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import dacite

from .errors import ValidationError

__all__ = ("as_dict", "from_dict")

T = TypeVar("T")
Expand Down Expand Up @@ -45,10 +43,7 @@ def _as_dict(_data: Dict[str, Any]) -> Dict[str, Any]:
if v is not None
}

try:
return _as_dict(asdict(data))
except Exception as e:
raise ValidationError(e)
return _as_dict(asdict(data))


def from_dict(data_class: Type[T], data: Dict[str, Any]) -> T:
Expand Down Expand Up @@ -81,7 +76,4 @@ def _from_dict(_data: Dict[str, Any]) -> Dict[str, Any]:
for k, v in _data.items()
}

try:
return dacite.from_dict(data_class=data_class, data=_from_dict(data), config=config)
except Exception as e:
raise ValidationError(e)
return dacite.from_dict(data_class=data_class, data=_from_dict(data), config=config)

0 comments on commit 7b6d033

Please sign in to comment.