Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve django-import-export #13402

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@
"stubs/corus",
"stubs/dateparser",
"stubs/defusedxml",
"stubs/django-import-export",
"stubs/docker",
"stubs/docutils",
"stubs/Flask-SocketIO",
2 changes: 1 addition & 1 deletion stubs/django-import-export/import_export/admin.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
14 changes: 7 additions & 7 deletions stubs/django-import-export/import_export/resources.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
2 changes: 1 addition & 1 deletion stubs/django-import-export/import_export/results.pyi
Original file line number Diff line number Diff line change
@@ -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]]: ...
12 changes: 8 additions & 4 deletions stubs/django-import-export/import_export/tmp_storages.pyi
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
from abc import abstractmethod
from typing import IO, Any, ClassVar

class BaseStorage:
name: str | None
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: ...

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: ...
6 changes: 3 additions & 3 deletions stubs/django-import-export/import_export/widgets.pyi
Original file line number Diff line number Diff line change
@@ -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: ...