griffe icon indicating copy to clipboard operation
griffe copied to clipboard

Default value of kwargs

Open AntoineD opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. I was very puzzled by seeing that the rendered **kwargs of a parameter has a default value and that the value is {}. My very fist thought was that the rendered code had this mutable as default value, but it was not (and cannot be obviously). Then I've been wondering that it could be a bug in the mkdocs stack so I've looked up and found in griffe in the code where it was set. Finally it seems legit (explicitly passing an empty dict would produce the same effect), but that's quite surprising!

Describe the solution you'd like Maybe do not show a default value at all?

Additional context That may also applies to *args.

AntoineD avatar Jul 24 '23 19:07 AntoineD

Personally I find this intuitive: if you don't pass any extra keyword argument, then the kwarg variable is an empty dict (and the args variable in an empty tuple), and you can use them as such.

But seeing how others get sometimes confused by this, we could probably not show anything in the "default" column indeed. The issue is, it bothers me to change that in Griffe itself, as this is technically correct in terms of API signature I think. Maybe we could override that in the Python handler of mkdocstrings instead.

pawamoy avatar Jul 24 '23 20:07 pawamoy

I'll close for now. I don't see a better alternative yet. Feel free to comment further :slightly_smiling_face:

pawamoy avatar Aug 09 '24 19:08 pawamoy