sanic-org / sanic-ext

Extended Sanic functionality
https://sanic.dev/en/plugins/sanic-ext/getting-started.html
MIT License
50 stars 36 forks source link

[Bug] Dependeny Injection throw exceptions by default if @classmethod constructors don't return value/objects #224

Open eisenhaus335 opened 1 year ago

eisenhaus335 commented 1 year ago

Describe the bug Dependency Injection do not have exception when constructors don't return object. It be nice if constructors given exception warning when no returned object to warn ahead. But if no-return constructor on dependency injection is expected is also reasonable pattern because we could make if for example if context == null: do something. But i believe first pattern is better for other not stumble around null objects

To Reproduce

@dataclass
class ContextInjection:
    request: Request

    @classmethod
    async def parse_htmx(cls, request: Request):
        # I do something on header here for example
        request.headers["header-X"] = true
        cls(request)

Environment (please complete the following information):