Skip to content

Commit

Permalink
Delete unused stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Nov 6, 2023
1 parent caaab97 commit 9dc8ff8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 43 deletions.
1 change: 0 additions & 1 deletion inngest/_internal/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ErrorCode(enum.Enum):
INVALID_BODY = "invalid_body"
INVALID_FUNCTION_CONFIG = "invalid_function_config"
INVALID_REQUEST_SIGNATURE = "invalid_request_signature"
INVALID_TRANSFORM = "invalid_transform"
MISMATCHED_SYNC = "mismatched_sync"
MISSING_EVENT_KEY = "missing_event_key"
MISSING_FUNCTION = "missing_function"
Expand Down
4 changes: 0 additions & 4 deletions inngest/_internal/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def _equals(key: EnvKey, value: str) -> _EnvCheck:
return _EnvCheck(expected=value, key=key, operator="equals")


def _is_truthy(key: EnvKey) -> _EnvCheck:
return _EnvCheck(expected=None, key=key, operator="is_truthy")


def _starts_with(key: EnvKey, value: str) -> _EnvCheck:
return _EnvCheck(expected=value, key=key, operator="starts_with")

Expand Down
10 changes: 0 additions & 10 deletions inngest/_internal/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,6 @@ def __init__(self, message: str | None = None) -> None:
)


class InvalidTransformError(InternalError):
status_code: int = http.HTTPStatus.INTERNAL_SERVER_ERROR

def __init__(self, message: str | None = None) -> None:
super().__init__(
code=const.ErrorCode.INVALID_TRANSFORM,
message=message,
)


class MissingEventKeyError(InternalError):
status_code: int = http.HTTPStatus.INTERNAL_SERVER_ERROR

Expand Down
41 changes: 22 additions & 19 deletions inngest/_internal/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _Config:


@typing.runtime_checkable
class FunctionHandlerAsync(typing.Protocol):
class _FunctionHandlerAsync(typing.Protocol):
def __call__(
self,
*,
Expand All @@ -45,7 +45,7 @@ def __call__(


@typing.runtime_checkable
class FunctionHandlerSync(typing.Protocol):
class _FunctionHandlerSync(typing.Protocol):
def __call__(
self,
*,
Expand All @@ -60,26 +60,26 @@ def __call__(


def _is_function_handler_async(
value: FunctionHandlerAsync | FunctionHandlerSync,
) -> typing.TypeGuard[FunctionHandlerAsync]:
value: _FunctionHandlerAsync | _FunctionHandlerSync,
) -> typing.TypeGuard[_FunctionHandlerAsync]:
return inspect.iscoroutinefunction(value)


def _is_function_handler_sync(
value: FunctionHandlerAsync | FunctionHandlerSync,
) -> typing.TypeGuard[FunctionHandlerSync]:
value: _FunctionHandlerAsync | _FunctionHandlerSync,
) -> typing.TypeGuard[_FunctionHandlerSync]:
return not inspect.iscoroutinefunction(value)


class FunctionOpts(types.BaseModel):
class _FunctionOpts(types.BaseModel):
model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)

batch_events: function_config.Batch | None = None
cancel: list[function_config.Cancel] | None = None
debounce: function_config.Debounce | None = None
id: str
name: str | None = None
on_failure: FunctionHandlerAsync | FunctionHandlerSync | None = None
on_failure: _FunctionHandlerAsync | _FunctionHandlerSync | None = None
rate_limit: function_config.RateLimit | None = None
retries: int | None = None
throttle: function_config.Throttle | None = None
Expand All @@ -102,12 +102,12 @@ def create_function(
]
| None = None,
name: str | None = None,
on_failure: FunctionHandlerAsync | FunctionHandlerSync | None = None,
on_failure: _FunctionHandlerAsync | _FunctionHandlerSync | None = None,
rate_limit: function_config.RateLimit | None = None,
retries: int | None = None,
throttle: function_config.Throttle | None = None,
trigger: function_config.TriggerCron | function_config.TriggerEvent,
) -> typing.Callable[[FunctionHandlerAsync | FunctionHandlerSync], Function]:
) -> typing.Callable[[_FunctionHandlerAsync | _FunctionHandlerSync], Function]:
"""
Create an Inngest function.
Expand All @@ -127,9 +127,11 @@ def create_function(
trigger: What should trigger runs of this function.
"""

def decorator(func: FunctionHandlerAsync | FunctionHandlerSync) -> Function:
def decorator(
func: _FunctionHandlerAsync | _FunctionHandlerSync
) -> Function:
return Function(
FunctionOpts(
_FunctionOpts(
batch_events=batch_events,
cancel=cancel,
debounce=debounce,
Expand All @@ -149,9 +151,9 @@ def decorator(func: FunctionHandlerAsync | FunctionHandlerSync) -> Function:


class Function:
_handler: FunctionHandlerAsync | FunctionHandlerSync
_handler: _FunctionHandlerAsync | _FunctionHandlerSync
_on_failure_fn_id: str | None = None
_opts: FunctionOpts
_opts: _FunctionOpts
_trigger: function_config.TriggerCron | function_config.TriggerEvent

@property
Expand Down Expand Up @@ -179,9 +181,9 @@ def on_failure_fn_id(self) -> str | None:

def __init__(
self,
opts: FunctionOpts,
opts: _FunctionOpts,
trigger: function_config.TriggerCron | function_config.TriggerEvent,
handler: FunctionHandlerAsync | FunctionHandlerSync,
handler: _FunctionHandlerAsync | _FunctionHandlerSync,
middleware: list[
type[middleware_lib.Middleware | middleware_lib.MiddlewareSync]
]
Expand Down Expand Up @@ -229,7 +231,7 @@ async def call(
return execution.CallError.from_error(err)

try:
handler: FunctionHandlerAsync | FunctionHandlerSync
handler: _FunctionHandlerAsync | _FunctionHandlerSync
if self.id == fn_id:
handler = self._handler
elif self.on_failure_fn_id == fn_id:
Expand Down Expand Up @@ -277,7 +279,8 @@ async def call(
),
)
else:
# Should be unreachable.
# Should be unreachable but Python's custom type guards don't
# support negative checks :(
return execution.CallError.from_error(
errors.UnknownError(
"unable to determine function handler type"
Expand Down Expand Up @@ -342,7 +345,7 @@ def call_sync(
middleware.before_execution_sync()

try:
handler: FunctionHandlerAsync | FunctionHandlerSync
handler: _FunctionHandlerAsync | _FunctionHandlerSync
if self.id == fn_id:
handler = self._handler
elif self.on_failure_fn_id == fn_id:
Expand Down
9 changes: 0 additions & 9 deletions inngest/_internal/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import json
import logging
import typing

Expand All @@ -23,14 +22,6 @@
SerializableT = typing.TypeVar("SerializableT", bound=Serializable)


def is_serializable(obj: object) -> typing.TypeGuard[Serializable]:
try:
json.dumps(obj)
return True
except Exception:
return False


class BaseModel(pydantic.BaseModel):
model_config = pydantic.ConfigDict(strict=True)

Expand Down

0 comments on commit 9dc8ff8

Please sign in to comment.