Skip to content

Commit 355a830

Browse files
committed
replace OrderedDict with dict
This change replaces `OrderedDict` with `dict` as done in encode/django-rest-framework#8964. This does not look like it has been released yet, but since this package requires Python 3.8 which is > Python 3.5, which was the last release to need `OrderedDict`, then this change should be safe to merge now. It should also be safe because `dict` is a superclass of `OrderedDict` and should not change anything for users who are using `OrderedDict` still.
1 parent dbe5007 commit 355a830

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

rest_framework-stubs/fields.pyi

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22
import uuid
3-
from collections import OrderedDict
43
from collections.abc import Callable, Generator, Iterable, Mapping, MutableMapping, Sequence
54
from decimal import Decimal
65
from enum import Enum
@@ -46,10 +45,10 @@ class Option(Protocol):
4645
def is_simple_callable(obj: Callable) -> bool: ...
4746
def get_attribute(instance: Any, attrs: list[str] | None) -> Any: ...
4847
def set_value(dictionary: MutableMapping[str, Any], keys: Sequence[str], value: Any) -> None: ...
49-
def to_choices_dict(choices: Iterable[Any]) -> OrderedDict: ...
50-
def flatten_choices_dict(choices: dict[Any, Any]) -> OrderedDict: ...
48+
def to_choices_dict(choices: Iterable[Any]) -> dict: ...
49+
def flatten_choices_dict(choices: dict[Any, Any]) -> dict: ...
5150
def iter_options(
52-
grouped_choices: OrderedDict, cutoff: int | None = ..., cutoff_text: StrOrPromise | None = ...
51+
grouped_choices: dict, cutoff: int | None = ..., cutoff_text: StrOrPromise | None = ...
5352
) -> Generator[Option, None, None]: ...
5453
def get_error_detail(exc_info: Any) -> Any: ...
5554

@@ -454,9 +453,9 @@ class ChoiceField(Field[str, str | int | tuple[str | int, str | int | tuple], st
454453
html_cutoff: int | None
455454
html_cutoff_text: StrOrPromise | None
456455
allow_blank: bool
457-
grouped_choices: OrderedDict
456+
grouped_choices: dict
458457
choice_strings_to_values: dict[str, Any]
459-
_choices: OrderedDict
458+
_choices: dict
460459
def __init__(
461460
self,
462461
choices: Iterable[Any],

rest_framework-stubs/relations.pyi

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
from collections.abc import Callable, Iterable, Mapping, Sequence
32
from typing import Any, Generic, TypeVar
43

@@ -62,11 +61,11 @@ class RelatedField(Generic[_MT, _DT, _PT], Field[_MT, _DT, _PT, Any]):
6261
def many_init(cls, *args: Any, **kwargs: Any) -> ManyRelatedField: ...
6362
def get_queryset(self) -> QuerySet[_MT]: ...
6463
def use_pk_only_optimization(self) -> bool: ...
65-
def get_choices(self, cutoff: int | None = ...) -> OrderedDict: ...
64+
def get_choices(self, cutoff: int | None = ...) -> dict: ...
6665
@property
67-
def choices(self) -> OrderedDict: ...
66+
def choices(self) -> dict: ...
6867
@property
69-
def grouped_choices(self) -> OrderedDict: ...
68+
def grouped_choices(self) -> dict: ...
7069
def iter_options(self) -> Iterable[Option]: ...
7170
def get_attribute(self, instance: _MT) -> _PT | None: ... # type: ignore[override]
7271
def display_value(self, instance: _MT) -> str: ...
@@ -182,9 +181,9 @@ class ManyRelatedField(Field[Sequence[Any], Sequence[Any], list[Any], Any]):
182181
child_relation: RelatedField = ...,
183182
): ...
184183
def get_value(self, dictionary: Mapping[Any, Any]) -> list[Any]: ... # type: ignore[override]
185-
def get_choices(self, cutoff: int | None = ...) -> OrderedDict: ...
184+
def get_choices(self, cutoff: int | None = ...) -> dict: ...
186185
@property
187-
def choices(self) -> OrderedDict: ...
186+
def choices(self) -> dict: ...
188187
@property
189-
def grouped_choices(self) -> OrderedDict: ...
188+
def grouped_choices(self) -> dict: ...
190189
def iter_options(self) -> Iterable[Option]: ...

rest_framework-stubs/schemas/coreapi.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import Counter, OrderedDict
1+
from collections import Counter
22
from collections.abc import Iterable, Sequence
33
from typing import Any
44

@@ -17,7 +17,7 @@ def distribute_links(obj: Any) -> None: ...
1717

1818
INSERT_INTO_COLLISION_FMT: str
1919

20-
class LinkNode(OrderedDict):
20+
class LinkNode(dict):
2121
links: list[Any]
2222
methods_counter: Counter
2323
def __init__(self) -> None: ...

rest_framework-stubs/utils/serializer_helpers.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from collections import OrderedDict
21
from collections.abc import Iterator, MutableMapping
32
from typing import Any
43

54
from rest_framework.exceptions import ErrorDetail
65
from rest_framework.fields import Field
76
from rest_framework.serializers import BaseSerializer
87

9-
class ReturnDict(OrderedDict):
8+
class ReturnDict(dict):
109
serializer: BaseSerializer
1110
def __init__(self, serializer: BaseSerializer = ..., *args, **kwargs): ...
1211
def copy(self) -> ReturnDict: ...
@@ -39,7 +38,7 @@ class NestedBoundField(BoundField):
3938

4039
class BindingDict(MutableMapping[str, Field]):
4140
serializer: BaseSerializer
42-
fields: OrderedDict[str, Field]
41+
fields: dict[str, Field]
4342
def __init__(self, serializer: BaseSerializer): ...
4443
def __setitem__(self, key: str, field: Field) -> None: ...
4544
def __getitem__(self, key: str) -> Field: ...

rest_framework-stubs/viewsets.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import OrderedDict
21
from collections.abc import Callable
32
from typing import Any
43

@@ -36,7 +35,7 @@ class ViewSetMixin:
3635
def reverse_action(self, url_name: str, *args: Any, **kwargs: Any) -> str: ...
3736
@classmethod
3837
def get_extra_actions(cls) -> list[_ViewFunc]: ...
39-
def get_extra_action_url_map(self) -> OrderedDict[str, str]: ...
38+
def get_extra_action_url_map(self) -> dict[str, str]: ...
4039

4140
class ViewSet(ViewSetMixin, views.APIView): ...
4241
class GenericViewSet(ViewSetMixin, generics.GenericAPIView[_MT_co]): ...

0 commit comments

Comments
 (0)