diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 18439b1b27cd..5d2fdedc76a2 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -44,7 +44,6 @@ "stubs/corus", "stubs/dateparser", "stubs/defusedxml", - "stubs/django-import-export", "stubs/docker", "stubs/docutils", "stubs/Flask-SocketIO", diff --git a/stubs/django-import-export/import_export/admin.pyi b/stubs/django-import-export/import_export/admin.pyi index 9805df5cdc79..6578d569f8b8 100644 --- a/stubs/django-import-export/import_export/admin.pyi +++ b/stubs/django-import-export/import_export/admin.pyi @@ -105,7 +105,7 @@ class ImportExportModelAdmin(ImportExportMixin[_ModelT], admin.ModelAdmin[_Model class ExportActionMixin(ExportMixin[_ModelT]): action_form: type[ActionForm] def __init__(self, *args: Any, **kwargs: Any) -> None: ... - def export_admin_action(self, request: HttpRequest, queryset: QuerySet[_ModelT]): ... + def export_admin_action(self, request: HttpRequest, queryset: QuerySet[_ModelT]) -> HttpResponse: ... def get_actions(self, request: HttpRequest) -> dict[str, tuple[Callable[..., str], str, str] | None]: ... @property def media(self) -> Media: ... diff --git a/stubs/django-import-export/import_export/resources.pyi b/stubs/django-import-export/import_export/resources.pyi index 3aad1cae9f72..895b430ccf9d 100644 --- a/stubs/django-import-export/import_export/resources.pyi +++ b/stubs/django-import-export/import_export/resources.pyi @@ -1,4 +1,4 @@ -from _typeshed import Incomplete +import _typeshed from collections import OrderedDict from collections.abc import Iterator, Sequence from functools import partial @@ -14,7 +14,7 @@ from .instance_loaders import BaseInstanceLoader from .results import Error, Result, RowResult from .widgets import ForeignKeyWidget, ManyToManyWidget, Widget -Dataset: TypeAlias = Incomplete # tablib.Dataset +Dataset: TypeAlias = _typeshed.Incomplete # tablib.Dataset logger: Logger @overload @@ -47,7 +47,7 @@ class ResourceOptions(Generic[_ModelT]): use_natural_foreign_keys: bool class DeclarativeMetaclass(type): - def __new__(cls, name: str, bases: tuple[type[Any], ...], attrs: dict[str, Any]): ... + def __new__(cls: type[_typeshed.Self], name: str, bases: tuple[type[Any], ...], attrs: dict[str, Any]) -> _typeshed.Self: ... class Diff: left: list[str] @@ -202,23 +202,23 @@ class Resource(Generic[_ModelT], metaclass=DeclarativeMetaclass): def export(self, *args: Any, queryset: QuerySet[_ModelT] | None = None, **kwargs: Any) -> Dataset: ... class ModelDeclarativeMetaclass(DeclarativeMetaclass): - def __new__(cls, name: str, bases: tuple[type[Any], ...], attrs: dict[str, Any]): ... + def __new__(cls: type[_typeshed.Self], name: str, bases: tuple[type[Any], ...], attrs: dict[str, Any]) -> _typeshed.Self: ... class ModelResource(Resource[_ModelT], metaclass=ModelDeclarativeMetaclass): DEFAULT_RESOURCE_FIELD: ClassVar[type[Field]] = ... WIDGETS_MAP: ClassVar[dict[str, type[Widget]]] @classmethod - def get_m2m_widget(cls, field: DjangoField[Any, Any]) -> partial[ManyToManyWidget]: ... + def get_m2m_widget(cls, field: DjangoField[Any, Any]) -> partial[ManyToManyWidget[Any]]: ... @classmethod def get_fk_widget(cls, field: DjangoField[Any, Any]) -> partial[ForeignKeyWidget[Any]]: ... @classmethod - def widget_from_django_field(cls, f: DjangoField[Any, Any], default: type[Widget] = ...): ... + def widget_from_django_field(cls, f: DjangoField[Any, Any], default: type[Widget] = ...) -> type[Widget]: ... @classmethod def widget_kwargs_for_field(self, field_name: str) -> dict[str, Any]: ... @classmethod def field_from_django_field(cls, field_name: str, django_field: DjangoField[Any, Any], readonly: bool) -> Field: ... def get_queryset(self) -> QuerySet[_ModelT]: ... - def init_instance(self, row: dict[str, Any] | None = None): ... + def init_instance(self, row: dict[str, Any] | None = None) -> _ModelT: ... def after_import(self, dataset: Dataset, result: Result, using_transactions: bool, dry_run: bool, **kwargs: Any) -> None: ... @classmethod def get_display_name(cls) -> str: ... diff --git a/stubs/django-import-export/import_export/results.pyi b/stubs/django-import-export/import_export/results.pyi index 249cb31fae20..dd50fd7e7e39 100644 --- a/stubs/django-import-export/import_export/results.pyi +++ b/stubs/django-import-export/import_export/results.pyi @@ -64,7 +64,7 @@ class Result: def append_row_result(self, row_result: RowResult) -> None: ... def append_base_error(self, error: Error) -> None: ... def add_dataset_headers(self, headers: list[str] | None) -> None: ... - def append_failed_row(self, row: dict[str, Any], error) -> None: ... + def append_failed_row(self, row: dict[str, Any], error: Exception) -> None: ... def append_invalid_row(self, number: int, row: dict[str, Any], validation_error: ValidationError) -> None: ... def increment_row_result_total(self, row_result: RowResult) -> None: ... def row_errors(self) -> list[tuple[int, Any]]: ... diff --git a/stubs/django-import-export/import_export/tmp_storages.pyi b/stubs/django-import-export/import_export/tmp_storages.pyi index ddab041ee2a9..eda138ffda97 100644 --- a/stubs/django-import-export/import_export/tmp_storages.pyi +++ b/stubs/django-import-export/import_export/tmp_storages.pyi @@ -1,3 +1,4 @@ +from abc import abstractmethod from typing import IO, Any, ClassVar class BaseStorage: @@ -5,13 +6,16 @@ class BaseStorage: read_mode: str encoding: str | None def __init__(self, *, name: str | None = None, read_mode: str = "", encoding: str | None = None) -> None: ... + @abstractmethod def save(self, data: Any) -> None: ... - def read(self) -> None: ... + @abstractmethod + def read(self) -> Any: ... # `Any` because `read` returns things from `save` + @abstractmethod def remove(self) -> None: ... class TempFolderStorage(BaseStorage): def save(self, data: Any) -> None: ... - def read(self): ... + def read(self) -> Any: ... def remove(self) -> None: ... def get_full_path(self) -> str: ... @@ -19,12 +23,12 @@ class CacheStorage(BaseStorage): CACHE_LIFETIME: int CACHE_PREFIX: str def save(self, data: Any) -> None: ... - def read(self): ... + def read(self) -> Any: ... def remove(self) -> None: ... class MediaStorage(BaseStorage): MEDIA_FOLDER: ClassVar[str] def save(self, data: IO[Any]) -> None: ... - def read(self): ... + def read(self) -> Any: ... def remove(self) -> None: ... def get_full_path(self) -> str: ... diff --git a/stubs/django-import-export/import_export/widgets.pyi b/stubs/django-import-export/import_export/widgets.pyi index 58d7cae69917..e91d2a424124 100644 --- a/stubs/django-import-export/import_export/widgets.pyi +++ b/stubs/django-import-export/import_export/widgets.pyi @@ -59,8 +59,8 @@ class ForeignKeyWidget(Widget, Generic[_ModelT]): def __init__(self, model: _ModelT, field: str = "pk", use_natural_foreign_keys: bool = False, **kwargs: Any) -> None: ... def get_queryset(self, value: Any, row: Mapping[str, Any], *args: Any, **kwargs: Any) -> QuerySet[_ModelT]: ... -class ManyToManyWidget(Widget): - model: Model +class ManyToManyWidget(Widget, Generic[_ModelT]): + model: _ModelT separator: str field: str - def __init__(self, model, separator: str | None = None, field: str | None = None, **kwargs: Any) -> None: ... + def __init__(self, model: _ModelT, separator: str | None = None, field: str | None = None, **kwargs: Any) -> None: ...