From 01d399c1efc7e3d69e4d66c9c1e1cf138b3d94c2 Mon Sep 17 00:00:00 2001 From: pytlab Date: Tue, 12 Dec 2017 21:19:18 +0800 Subject: [PATCH] Fix bug in precisions type checking. --- gaft/components/individual.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/gaft/components/individual.py b/gaft/components/individual.py index 2e79f87..9c94ab9 100644 --- a/gaft/components/individual.py +++ b/gaft/components/individual.py @@ -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):