Skip to content

Commit

Permalink
Fix an issue with Bounded values using falsey slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
dangle committed Nov 12, 2017
1 parent cabc5b1 commit ce8f5a7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions typet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def __new__(cls, __value, *args, **kwargs):
instance = instantiate(
BaseClass, type_, __value, *args, **kwargs)
cmp_val = keyfunc(instance)
if bound.start or bound.stop:
if bound.start and cmp_val < bound.start:
if bound.start is not None or bound.stop is not None:
if bound.start is not None and cmp_val < bound.start:
if keyfunc is not identity:
raise ValueError(
'The value of {}({}) [{}] is below the minimum'
Expand All @@ -157,7 +157,7 @@ def __new__(cls, __value, *args, **kwargs):
raise ValueError(
'The value {} is below the minimum allowed value '
'of {}.'.format(repr(__value), bound.start))
if bound.stop and cmp_val > bound.stop:
if bound.stop is not None and cmp_val > bound.stop:
if keyfunc is not identity:
raise ValueError(
'The value of {}({}) [{}] is above the maximum'
Expand Down Expand Up @@ -288,9 +288,9 @@ def _get_bound_repr(bound):
Returns:
A string representing the slice.
"""
if bound.start and not bound.stop:
if bound.start is not None and bound.stop is None:
return '{}:'.format(bound.start)
if bound.stop and not bound.start:
if bound.stop is not None and bound.start is None:
return ':{}'.format(bound.stop)
return '{}:{}'.format(bound.start, bound.stop)

Expand Down

0 comments on commit ce8f5a7

Please sign in to comment.