To add some type safety to the obj attribute of the Context class, I was thinking maybe it could be made generic with respect to obj attribute. It could then be used this way (with a TypedDict but it could be any user defined object):
class ContextObj(TypedDict):
attr: int
def subcommand(
ctx: click.Context[ContextObj],
...
) -> None:
reveal_type(ctx.obj["attr"]) # Revealed type is "int"
That might be a bit cumbersome, so I'd understand if this is rejected (but I'm open to alternatives). Otherwise, I will be happy to implement this
To add some type safety to the
objattribute of theContextclass, I was thinking maybe it could be made generic with respect toobjattribute. It could then be used this way (with aTypedDictbut it could be any user defined object):That might be a bit cumbersome, so I'd understand if this is rejected (but I'm open to alternatives). Otherwise, I will be happy to implement this