Skip to content

Commit 62cb408

Browse files
committed
Cleanups from Sonar scan
1 parent 3dcc94b commit 62cb408

4 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/odin/mapping/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ def __getitem__(self, idx):
480480

481481

482482
class MappingBase:
483-
from_obj: type = None
484-
to_obj: type = None
483+
from_obj: Optional[type] = None
484+
to_obj: Optional[type] = None
485485

486486
# Pending deprecation, move to from_obj and to_obj terminology
487487
from_resource = None
@@ -747,8 +747,8 @@ class ImmediateMapping(MappingBase, metaclass=MappingMeta):
747747
def map_field(
748748
func: _F = None,
749749
*,
750-
from_field: str = None,
751-
to_field: str = None,
750+
from_field: Union[None, str, Sequence[str]] = None,
751+
to_field: Union[None, str, Sequence[str]] = None,
752752
to_list: bool = False,
753753
) -> Union[_F, Callable[[_F], _F]]:
754754
"""Field decorator for custom mappings.
@@ -771,8 +771,8 @@ def inner(fun):
771771
def map_list_field(
772772
func: _F = None,
773773
*,
774-
from_field: str = None,
775-
to_field: str = None,
774+
from_field: Union[None, str, Sequence[str]] = None,
775+
to_field: Union[None, str, Sequence[str]] = None,
776776
) -> Union[_F, Callable[[_F], _F]]:
777777
"""Field decorator for custom mappings that return a single list.
778778
@@ -787,7 +787,7 @@ def map_list_field(
787787
def assign_field(
788788
func: _F = None,
789789
*,
790-
to_field: str = None,
790+
to_field: Union[None, str, Sequence[str]] = None,
791791
to_list: bool = False,
792792
) -> Union[_F, Callable[[_F], _F]]:
793793
"""Field decorator for assigning a value to destination field without requiring a corresponding source field.

src/odin/traversal.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ def __next__(self) -> ResourceBase:
181181
else:
182182
self._field_iters.pop()
183183

184-
if self.current_resource:
185-
if hasattr(self, "on_exit"):
186-
self.on_exit()
184+
if self.current_resource and hasattr(self, "on_exit"):
185+
self.on_exit()
187186

188187
try:
189188
key, next_resource = next(self._resource_iters[-1])

src/odin/utils/ipv6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def is_valid_ipv6_address(ip_str):
5454
if hextet.count(".") == 3:
5555
# If we have an IPv4 mapped address, the IPv4 portion has to
5656
# be at the end of the IPv6 portion.
57-
if not ip_str.split(":")[-1] == hextet:
57+
if ip_str.split(":")[-1] != hextet:
5858
return False
5959
try:
6060
validate_ipv4_address(hextet)

src/odin/validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# A note: to use validators from the Django project install the baldr package. Baldr is an integration between Odin and
44
# the Django framework, the integration includes support for handling the Django version of the ValidationError
55
# exception within Odin.
6-
from typing import Callable, Any, Union, TypeVar
6+
from typing import Callable, Any, Union, TypeVar, Optional
77

88
import re
99

@@ -19,7 +19,7 @@ class RegexValidator:
1919
regex = r""
2020
message = "Enter a valid value."
2121
code = "invalid"
22-
description: str = None
22+
description: Optional[str] = None
2323

2424
def __init__(
2525
self,

0 commit comments

Comments
 (0)