Skip to content

Current status for decorators which use **kwargs? #1215

Answered by Akuli
acdha asked this question in Q&A
Discussion options

You must be logged in to vote

Not much has changed recently. You can override a method and keep the type unchanged (my @copy_type decorator). You can add positional arguments with Concatenate, although I don't think it's fully implemented in mypy. But as you say, there isn't anything for adding keyword arguments.

A couple alternatives:

  • If you have a lot of code calling your custom logger methods, you can copy/paste the definitions of debug(), info() etc into your custom logger class, maybe with if TYPE_CHECKING.

  • Just take **kwargs: Any in your custom methods, e.g.

    def info(self, *args: object, something_else: WhatEver = some_default_value, **kwargs: Any) -> None:
        super().info(*args, **kwargs, extra={"something…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@acdha
Comment options

Answer selected by acdha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants