jieter / django-tables2

django-tables2 - An app for creating HTML tables
https://django-tables2.readthedocs.io/en/latest/
Other
1.9k stars 429 forks source link

render() should have *args, **kwargs as param #916

Open nerdoc opened 1 year ago

nerdoc commented 1 year ago

https://github.com/jieter/django-tables2/blob/7a5a1fbf2bb5ce2ebe48e962b00c8ff327fea644/django_tables2/columns/base.py#L356

This method is called and can be declared with various parameters (dynamically determined by introspection) in subclasses.

IDEs like PyCharm help by finding out which params the inherited method has, to show you an error if the signature doesn't match.

So if you e.g. declare a Column like this:

class ActionButtonsColumn(tables.Column):
    def render(self, record: HolidayPolicy, value):
        ...

the IDE places a warning: grafik

By adding *args, **kwargs after value this problem can be solved, and does not impact other things IMHO.

However, I don't know much of the internals of django_tables2, so please feel free to close this issue if you think this is not helpful or affects other subsystems...

marksweb commented 1 year ago

You wouldn't replace value with **kwargs, but you could add *args, **kwargs to the signature.

The base render() needs to return value, so you need to make sure it gets an arg for value.

There's a good explanation of this here.

nerdoc commented 1 year ago

definitely, I'll change this above. Thanks for the hint.