Skip to content

Commit

Permalink
Use isdecimal in favor of isdigit
Browse files Browse the repository at this point in the history
  • Loading branch information
moomoohk committed Jan 8, 2023
1 parent b07cc6a commit 58b34df
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dpath/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get(obj, segments: Path):
if leaf(current):
raise PathNotFound(f"Path: {segments}[{i}]")

if isinstance(current, Sequence) and isinstance(segment, (str, bytes)) and segment.isdigit():
if isinstance(current, Sequence) and isinstance(segment, str) and segment.isdecimal():
segment = int(segment)

current = current[segment]
Expand Down Expand Up @@ -314,7 +314,7 @@ def _default_creator(
else:
segment_next = None

if isinstance(segment_next, int) or segment_next.isdigit():
if isinstance(segment_next, int) or (isinstance(segment_next, str) and segment_next.isdecimal()):
current[segment] = []
else:
current[segment] = {}
Expand Down Expand Up @@ -342,7 +342,7 @@ def set(
for (i, segment) in enumerate(segments[:-1]):

# If segment is non-int but supposed to be a sequence index
if isinstance(segment, (str, bytes)) and isinstance(current, Sequence) and segment.isdigit():
if isinstance(segment, str) and isinstance(current, Sequence) and segment.isdecimal():
segment = int(segment)

try:
Expand All @@ -364,7 +364,7 @@ def set(
last_segment = segments[-1]

# Resolve ambiguity of last segment
if isinstance(last_segment, (str, bytes)) and isinstance(current, Sequence) and last_segment.isdigit():
if isinstance(last_segment, str) and isinstance(current, Sequence) and last_segment.isdecimal():
last_segment = int(last_segment)

if isinstance(last_segment, int):
Expand Down

0 comments on commit 58b34df

Please sign in to comment.