Skip to content

Commit

Permalink
Added try except ImportError for collections.abc which will require a…
Browse files Browse the repository at this point in the history
… change from Python 3.8. Style follows similar usage elsewhere in deep.

Also easy to drop try/except when Python 2.7 may not be supported in the future.
  • Loading branch information
trhallam committed Sep 14, 2019
1 parent 99223a8 commit 63c479d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
6 changes: 5 additions & 1 deletion deap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class used as base class, for the fitness member of any individual. """

import sys

from collections import Sequence
try:
from collections.abc import Sequence
except ImportError:
from collections import Sequence

from copy import deepcopy
from functools import partial
from operator import mul, truediv
Expand Down
6 changes: 5 additions & 1 deletion deap/benchmarks/movingpeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
import math
import itertools
import random
from collections import Sequence

try:
from collections.abc import Sequence
except:
from colections import Sequence

def cone(individual, position, height, width):
"""The cone peak function to be used with scenario 2 and 3.
Expand Down
6 changes: 5 additions & 1 deletion deap/tools/constraint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

from functools import wraps
from itertools import repeat
from collections import Sequence

try:
from collections.abc import Sequence
except ImportError:
from collections import Sequence

class DeltaPenalty(object):
"""This decorator returns penalized fitness for invalid individuals and the
Expand Down
6 changes: 5 additions & 1 deletion deap/tools/crossover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import random
import warnings

from collections import Sequence
try:
from collections.abc import Sequence
except ImportError:
from collections import Sequence

from itertools import repeat


Expand Down
5 changes: 4 additions & 1 deletion deap/tools/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import random

from itertools import repeat
from collections import Sequence

try:
from collections.abc import Sequence
except ImportError:
from collections import Sequence

######################################
# GA Mutations #
Expand Down

0 comments on commit 63c479d

Please sign in to comment.