alanjds / drf-nested-routers

Nested Routers for Django Rest Framework
https://pypi.org/project/drf-nested-routers/
Apache License 2.0
1.66k stars 157 forks source link

PoC: Add detailed hints for `Nested*Router.__init__()` #345

Open intgr opened 4 months ago

intgr commented 4 months ago

I'm not sure if you want this complexity, but I wanted to demonstrate what can be still improved.

Because NestedMixin is declared as:

    def __init__(
        self,
        parent_router: SimpleRouter | DefaultRouter | NestedMixin,
        parent_prefix: str,
        *args: Any,
        **kwargs: Any
    ) -> None:

Typecheckers cannot see beyond the *args: Any, **kwargs: Any arguments, they will allow literally anything as long as the first 2 arguments are satisfied.

In order to fix this, it would be necessary to add complete signatures, duplicating the arguments from DRF itself.

alanjds commented 4 months ago

Typecheckers cannot see beyond the *args: Any, **kwargs: Any arguments, they will allow literally anything as long as the first 2 arguments are satisfied.

In order to fix this, it would be necessary to add complete signatures, duplicating the arguments from DRF itself.

I see.

What I would like is to inform what this mixing "soft-inherits" from, but without really creating an inheritance. Duplicating code from DRF is not something that I want. In fact, DRF made some small internal adjustment so drf-nested-routers got able to override just a little part of the routers, instead of copy-pasting some lines.

That makes me think that DRF may be open to small changes that facilitate what you want, if this does not reduce their code readability.