Skip to content

Commit

Permalink
Fixes wrong inheritances
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobessa committed Dec 2, 2024
1 parent df19974 commit ea47934
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
10 changes: 4 additions & 6 deletions vintasend/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

from vintasend.services.notification_adapters.base import BaseNotificationAdapter
from vintasend.services.notification_backends.base import BaseNotificationBackend
from vintasend.services.notification_template_renderers.base_templated_email_renderer import (
BaseTemplateRenderer,
)
from vintasend.services.notification_template_renderers.base import BaseNotificationTemplateRenderer


def _import_class(import_string: str) -> Any:
Expand Down Expand Up @@ -85,7 +83,7 @@ def get_notification_backend(
return cast(BaseNotificationBackend, backend)


def get_template_renderer(template_renderer_import_str: str) -> BaseTemplateRenderer:
def get_template_renderer(template_renderer_import_str: str) -> BaseNotificationTemplateRenderer:
try:
template_renderer_cls = _import_class(template_renderer_import_str)
except (ImportError, ModuleNotFoundError) as e:
Expand All @@ -100,9 +98,9 @@ def get_template_renderer(template_renderer_import_str: str) -> BaseTemplateRend
f"Notifications Template Renderer Error: Could not instantiate {template_renderer_import_str}"
) from e

if not isinstance(template_renderer, BaseTemplateRenderer):
if not isinstance(template_renderer, BaseNotificationTemplateRenderer):
raise ValueError(
f"Notifications Template Renderer Error: {template_renderer_import_str} is not a valid template renderer"
)

return cast(BaseTemplateRenderer, template_renderer)
return cast(BaseNotificationTemplateRenderer, template_renderer)
4 changes: 2 additions & 2 deletions vintasend/services/notification_adapters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING, cast, Generic, TypeVar, overload

from vintasend.services.notification_backends.base import BaseNotificationBackend
from vintasend.services.notification_template_renderers.base_templated_email_renderer import BaseTemplateRenderer
from vintasend.services.notification_template_renderers.base import BaseNotificationTemplateRenderer


if TYPE_CHECKING:
Expand All @@ -12,7 +12,7 @@


B = TypeVar("B", bound=BaseNotificationBackend)
T = TypeVar("T", bound=BaseTemplateRenderer)
T = TypeVar("T", bound=BaseNotificationTemplateRenderer)

class BaseNotificationAdapter(Generic[B, T], ABC):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from vintasend.services.notification_adapters.async_base import AsyncBaseNotificationAdapter
from vintasend.services.helpers import get_notification_backend, get_template_renderer
from vintasend.services.notification_backends.base import BaseNotificationBackend
from vintasend.services.notification_template_renderers.base_templated_email_renderer import BaseTemplateRenderer
from vintasend.services.notification_template_renderers.base_templated_email_renderer import BaseTemplatedEmailRenderer


B = TypeVar("B", bound=BaseNotificationBackend)
T = TypeVar("T", bound=BaseTemplateRenderer)
T = TypeVar("T", bound=BaseTemplatedEmailRenderer)

class FakeEmailAdapter(Generic[B, T], BaseNotificationAdapter[B, T]):
notification_type = NotificationTypes.EMAIL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from vintasend.constants import NotificationTypes
from vintasend.services.notification_adapters.base import BaseNotificationAdapter
from vintasend.services.helpers import get_notification_backend, get_template_renderer
from vintasend.services.notification_backends.base import BaseNotificationBackend
from vintasend.services.notification_template_renderers.base_templated_email_renderer import BaseTemplateRenderer
from vintasend.services.notification_template_renderers.base import BaseNotificationTemplateRenderer


if TYPE_CHECKING:
Expand All @@ -13,7 +12,7 @@


B = TypeVar("B", bound=BaseNotificationBackend)
T = TypeVar("T", bound=BaseTemplateRenderer)
T = TypeVar("T", bound=BaseNotificationTemplateRenderer)


class FakeInAppAdapter(Generic[B, T], BaseNotificationAdapter[B, T]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TemplatedEmail(NotificationSendInput):
body: str


class BaseTemplateRenderer(BaseNotificationTemplateRenderer):
class BaseTemplatedEmailRenderer(BaseNotificationTemplateRenderer):
@abstractmethod
def render(
self, notification: Notification, context: "NotificationContextDict"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from vintasend.exceptions import NotificationBodyTemplateRenderingError
from vintasend.services.notification_template_renderers.base_templated_email_renderer import (
BaseTemplateRenderer,
BaseTemplatedEmailRenderer,
TemplatedEmail,
)


class FakeTemplateRenderer(BaseTemplateRenderer):
class FakeTemplateRenderer(BaseTemplatedEmailRenderer):
def render(self, notification, context):
return TemplatedEmail(
subject=notification.subject_template, body=notification.body_template
)


class FakeTemplateRendererWithException(BaseTemplateRenderer):
class FakeTemplateRendererWithException(BaseTemplatedEmailRenderer):
def render(self, notification, context):
raise NotificationBodyTemplateRenderingError("Fake error")

Expand Down

0 comments on commit ea47934

Please sign in to comment.