jieter/django-tables2

Missing type hints

mschoettle opened this issue · 1 comments

We use mypy for type checking and django-stubs for the type stubs of Django.

Given a view defined as follows:

class FooModelListView(SingleTableView):
    model = FooModel
    queryset = FooModel.objects.all()
    table_class = FooModelClass

When overriding get_context_data to supply additional data to the template, the type hints from django-stubs are overriden since SingleTableMixin redeclares get_context_data without type hints. In django-stubs it is defined as:

def get_context_data(**kwargs: Any) -> Dict[str, Any]

Defining it like this in the above view

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
        context = super().get_context_data(**kwargs)
        ....
        return context

produces the following type error:

Returning Any from function declared to return "Dict[str, Any]" [no-any-return]

Would it be possible to add type hints? It might be helpful to have type hints overall but that is a bigger undertaking.

Yes, please open a PR to add type hints to get_context_data!