Typing: on_event
method is missing generic arguments
#1523
-
Pyright does not like the from starlette.applications import Starlette
app = Starlette()
@app.on_event('startup') # E: Untyped function decorator obscures type of function; ignoring decorator
async def on_startup() -> None:
pass This can be fixed by adding generic arguments to the F = TypeVar('F', bound=typing.Callable[..., Any])
def on_event(self, event_type: str) -> typing.Callable[[F], F]:
return self.router.on_event(event_type) I know the usage of these decorators is discouraged but it is necessary for some use cases: RobertCraigie/prisma-client-py#290 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Could you provide a context manager? This reduces the boilerplate a bit when used with Starlette. I don't think the team is too keen on adding more typing info, but @tomchristie can give the final word on it |
Beta Was this translation helpful? Give feedback.
-
Rather than use the decorator, use the plain ol' https://www.starlette.io/applications/ We don't document the decorator style anymore, and there's a code comment recommending against it. We'll move it to a more formal deprecation at some point. |
Beta Was this translation helpful? Give feedback.
-
The decorators are deprecated on the latest Starlette release. |
Beta Was this translation helpful? Give feedback.
The decorators are deprecated on the latest Starlette release.