Skip to content

Commit

Permalink
Fix bug in precisions type checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
PytLab committed Dec 12, 2017
1 parent a3a9f76 commit 01d399c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions gaft/components/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@ def __get__(self, obj, owner):
return self.__precisions

def __set__(self, obj, precisions):
if type(precisions) is float:
self.__precisions = [precisions]*len(obj.ranges)
else:
# Check.
if type(precisions) not in [tuple, list]:
raise TypeError('precisions must be a list of numbers')
if len(precisions) != len(obj.ranges):
raise ValueError('Lengths of eps and ranges should be the same')
for (a, b), eps in zip(obj.ranges, precisions):
if eps > (b - a):
msg = 'Invalid precision {} in range ({}, {})'.format(eps, a, b)
raise ValueError(msg)
self.__precisions = precisions
if type(precisions) in [int, float]:
precisions = [precisions]*len(obj.ranges)
# Check.
if type(precisions) not in [tuple, list]:
raise TypeError('precisions must be a list of numbers')
if len(precisions) != len(obj.ranges):
raise ValueError('Lengths of eps and ranges should be the same')
for (a, b), eps in zip(obj.ranges, precisions):
if eps > (b - a):
msg = 'Invalid precision {} in range ({}, {})'.format(eps, a, b)
raise ValueError(msg)
self.__precisions = precisions


class IndividualBase(object):
Expand Down

0 comments on commit 01d399c

Please sign in to comment.