Skip to content

Commit

Permalink
fix(serializers): BaseSerializer should return Self (#39)
Browse files Browse the repository at this point in the history
This fixes invalid type in following code:

```python
    def factory(
        serializer: Type[ModelSerializer],
        data: Dict[str, str],
    ) -> ModelSerializer:
        return serializer(data=data)
```

Without Self returned type is "BaseSerializer".
  • Loading branch information
last-partizan authored Jul 22, 2023
1 parent 5fb868d commit 9b3a693
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.7"
typing_extensions = { version = "^4.6", python = "<3.11" }

[tool.poetry.dev-dependencies]
ipython = "^7.19"
Expand Down
3 changes: 2 additions & 1 deletion rest_framework-stubs/serializers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from typing import (
Literal,
NoReturn,
)
from typing_extensions import Self

from django.db import models
from django.db.models import Manager, QuerySet
Expand Down Expand Up @@ -82,7 +83,7 @@ class BaseSerializer(Field[Any, Any, Any, Any]):
instance: Any | None
initial_data: Any
_context: dict[str, Any]
def __new__(cls, *args: Any, **kwargs: Any) -> BaseSerializer: ...
def __new__(cls, *args: Any, **kwargs: Any) -> Self: ...
def __class_getitem__(cls, *args: Any, **kwargs: Any) -> Any: ...
def __init__(
self,
Expand Down

0 comments on commit 9b3a693

Please sign in to comment.