diff --git a/inngest/_internal/const.py b/inngest/_internal/const.py index 8b866e92..d71937a9 100644 --- a/inngest/_internal/const.py +++ b/inngest/_internal/const.py @@ -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" diff --git a/inngest/_internal/env.py b/inngest/_internal/env.py index 73ceee2f..04fa7aa0 100644 --- a/inngest/_internal/env.py +++ b/inngest/_internal/env.py @@ -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") diff --git a/inngest/_internal/errors.py b/inngest/_internal/errors.py index 95591c48..264e973e 100644 --- a/inngest/_internal/errors.py +++ b/inngest/_internal/errors.py @@ -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 diff --git a/inngest/_internal/function.py b/inngest/_internal/function.py index 115e2ded..fd2b5300 100644 --- a/inngest/_internal/function.py +++ b/inngest/_internal/function.py @@ -30,7 +30,7 @@ class _Config: @typing.runtime_checkable -class FunctionHandlerAsync(typing.Protocol): +class _FunctionHandlerAsync(typing.Protocol): def __call__( self, *, @@ -45,7 +45,7 @@ def __call__( @typing.runtime_checkable -class FunctionHandlerSync(typing.Protocol): +class _FunctionHandlerSync(typing.Protocol): def __call__( self, *, @@ -60,18 +60,18 @@ 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 @@ -79,7 +79,7 @@ class FunctionOpts(types.BaseModel): 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 @@ -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. @@ -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, @@ -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 @@ -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] ] @@ -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: @@ -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" @@ -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: diff --git a/inngest/_internal/types.py b/inngest/_internal/types.py index 13bf0660..09faaff0 100644 --- a/inngest/_internal/types.py +++ b/inngest/_internal/types.py @@ -1,6 +1,5 @@ from __future__ import annotations -import json import logging import typing @@ -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)