Skip to content

Commit

Permalink
tiny cleanup to keep it dry
Browse files Browse the repository at this point in the history
  • Loading branch information
wbolster committed Jun 29, 2017
1 parent 1faccb9 commit fdf397c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/sanest/sanest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Collection(
CONTAINER_TYPES = (builtins.dict, builtins.list)
TYPES = CONTAINER_TYPES + ATOMIC_TYPES
PATH_SYNTAX_TYPES = (builtins.tuple, builtins.list)
STRING_LIKE_TYPES = (str, bytes, bytearray)

typeof = builtins.type

Expand Down Expand Up @@ -714,7 +715,7 @@ def __getitem__(self, path_like):
def __setitem__(self, path_like, value):
if type(path_like) is slice and is_regular_list_slice(path_like):
# slice assignment takes any iterable, like .extend()
if isinstance(value, (str, bytes, bytearray)):
if isinstance(value, STRING_LIKE_TYPES):
raise TypeError(
"expected iterable that is not string-like, "
"got {.__name__}".format(type(value)))
Expand Down Expand Up @@ -786,7 +787,7 @@ def append(self, value, *, type=None):
def extend(self, iterable, *, type=None):
if typeof(iterable) is typeof(self):
self._data.extend(iterable._data)
elif isinstance(iterable, (str, bytes, bytearray)):
elif isinstance(iterable, STRING_LIKE_TYPES):
raise TypeError(
"expected iterable that is not string-like, got {.__name__}"
.format(typeof(iterable)))
Expand Down

0 comments on commit fdf397c

Please sign in to comment.