2023-07-12 21:47:58 +01:00
|
|
|
from sanic import Request, Sanic
|
|
|
|
from sanic.config import Config
|
|
|
|
|
|
|
|
|
|
|
|
class CustomConfig(Config):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Foo:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class RequestContext:
|
|
|
|
foo: Foo
|
|
|
|
|
|
|
|
|
|
|
|
class CustomRequest(Request[Sanic[CustomConfig, Foo], RequestContext]):
|
|
|
|
@staticmethod
|
|
|
|
def make_context() -> RequestContext:
|
|
|
|
ctx = RequestContext()
|
|
|
|
ctx.foo = Foo()
|
|
|
|
return ctx
|
|
|
|
|
|
|
|
|
2023-10-25 04:13:13 +01:00
|
|
|
app = Sanic("test", config=CustomConfig(), ctx=Foo(), request_class=CustomRequest)
|
2023-07-12 21:47:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
|
|
|
async def handler(request: CustomRequest):
|
|
|
|
reveal_type(request)
|
|
|
|
reveal_type(request.ctx)
|
|
|
|
reveal_type(request.app)
|