Skip to content

Commit f2419e9

Browse files
committed
Typing improvements
1 parent 6c31d1a commit f2419e9

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/odin/annotated_resource/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
"""
1414

15-
from typing import Any, Dict, Iterable, Tuple, Type
15+
from collections.abc import Iterable
1616

1717
from odin import registration
1818
from odin.fields import BaseField
@@ -35,8 +35,9 @@
3535
)
3636

3737

38-
def _iterate_attrs(attrs: Dict[str, Any]) -> Iterable[Tuple[str, BaseField]]:
38+
def _iterate_attrs(attrs: dict[str, ...]) -> Iterable[tuple[str, BaseField]]:
3939
"""Iterate through attributes and combine with annotations."""
40+
4041
annotations = attrs.pop("__annotations__", None) or {}
4142

4243
# Yield any annotations processed into field instances
@@ -56,7 +57,7 @@ def __new__(
5657
name: str,
5758
bases,
5859
attrs: dict,
59-
meta_options_type: Type[MOT] = ResourceOptions,
60+
meta_options_type: type[MOT] = ResourceOptions,
6061
abstract: bool = False,
6162
):
6263
super_new = super().__new__
@@ -92,8 +93,8 @@ def __new__(
9293
return r
9394

9495
# Add all field attributes to the class.
95-
for name, field in _iterate_attrs(attrs):
96-
new_class.add_to_class(name, field)
96+
for field_name, field in _iterate_attrs(attrs):
97+
new_class.add_to_class(field_name, field)
9798

9899
_add_parent_fields_to_class(new_class, new_meta, parents)
99100

src/odin/annotated_resource/type_aliases.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Type aliases for string formatted types."""
2-
from typing import Any, Callable, Sequence, Tuple, Union
2+
3+
from collections.abc import Callable, Sequence
4+
from typing import Any
35

46
__all__ = (
57
"Email",
@@ -12,11 +14,7 @@
1214
)
1315

1416
Validator = Callable[[Any], None]
15-
Choices = Union[
16-
Sequence[Any],
17-
Sequence[Tuple[str, Any]],
18-
Sequence[Tuple[str, Any, str]],
19-
]
17+
Choices = Sequence[Any] | Sequence[tuple[str, Any]] | Sequence[tuple[str, Any, str]]
2018

2119

2220
class Email(str):

src/odin/contrib/sphinx/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sphinx.ext.autodoc import (
77
Documenter,
88
ModuleLevelDocumenter,
9-
ObjectMembers,
9+
ObjectMember,
1010
bool_option,
1111
)
1212
from sphinx.util import logging
@@ -145,7 +145,7 @@ def build_field_triple(self, field) -> tuple:
145145
"\n".join(details).split("\n"), # Details
146146
)
147147

148-
def get_object_members(self, want_all: bool) -> tuple[bool, ObjectMembers]:
148+
def get_object_members(self, want_all: bool) -> tuple[bool, ObjectMember]:
149149
pass # Not required; this implementation replaces the document_members method that calls get_object_members
150150

151151
def document_members(self, all_members: bool = False) -> None:

0 commit comments

Comments
 (0)