From: Christian Kastner <ckk@debian.org>
Date: Fri, 24 Jan 2020 17:58:41 +0100
Subject: Python 3 syntax fixes

setup.py uses 2to3=True to automatically convert syntax from Python 2 to 3
during build, but sphinx trips over the Python 2 syntax in the original source.
---
 deap/algorithms.py                                   | 14 +++++++-------
 deap/base.py                                         |  6 +++---
 deap/benchmarks/movingpeaks.py                       |  4 ++--
 deap/gp.py                                           | 16 ++++++++--------
 deap/tests/test_logbook.py                           |  2 +-
 deap/tools/support.py                                |  6 +++---
 doc/code/tutorials/part_3/3_next_step.py             | 14 +++++++-------
 doc/code/tutorials/part_4/4_4_Using_Cpp_NSGA.py      | 20 ++++++++++----------
 doc/code/tutorials/part_4/4_5_home_made_eval_func.py | 14 +++++++-------
 doc/tutorials/advanced/numpy.rst                     |  4 ++--
 10 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/deap/algorithms.py b/deap/algorithms.py
index 4105fef..7e13333 100644
--- a/deap/algorithms.py
+++ b/deap/algorithms.py
@@ -157,7 +157,7 @@ def eaSimple(population, toolbox, cxpb, mutpb, ngen, stats=None,
     record = stats.compile(population) if stats else {}
     logbook.record(gen=0, nevals=len(invalid_ind), **record)
     if verbose:
-        print logbook.stream
+        print(logbook.stream)
 
     # Begin the generational process
     for gen in range(1, ngen + 1):
@@ -184,7 +184,7 @@ def eaSimple(population, toolbox, cxpb, mutpb, ngen, stats=None,
         record = stats.compile(population) if stats else {}
         logbook.record(gen=gen, nevals=len(invalid_ind), **record)
         if verbose:
-            print logbook.stream
+            print(logbook.stream)
 
     return population, logbook
 
@@ -308,7 +308,7 @@ def eaMuPlusLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,
     record = stats.compile(population) if stats is not None else {}
     logbook.record(gen=0, nevals=len(invalid_ind), **record)
     if verbose:
-        print logbook.stream
+        print(logbook.stream)
 
     # Begin the generational process
     for gen in range(1, ngen + 1):
@@ -332,7 +332,7 @@ def eaMuPlusLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,
         record = stats.compile(population) if stats is not None else {}
         logbook.record(gen=gen, nevals=len(invalid_ind), **record)
         if verbose:
-            print logbook.stream
+            print(logbook.stream)
 
     return population, logbook
 
@@ -409,7 +409,7 @@ def eaMuCommaLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,
     record = stats.compile(population) if stats is not None else {}
     logbook.record(gen=0, nevals=len(invalid_ind), **record)
     if verbose:
-        print logbook.stream
+        print(logbook.stream)
 
     # Begin the generational process
     for gen in range(1, ngen + 1):
@@ -433,7 +433,7 @@ def eaMuCommaLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,
         record = stats.compile(population) if stats is not None else {}
         logbook.record(gen=gen, nevals=len(invalid_ind), **record)
         if verbose:
-            print logbook.stream
+            print(logbook.stream)
     return population, logbook
 
 
@@ -494,6 +494,6 @@ def eaGenerateUpdate(toolbox, ngen, halloffame=None, stats=None,
         record = stats.compile(population) if stats is not None else {}
         logbook.record(gen=gen, nevals=len(population), **record)
         if verbose:
-            print logbook.stream
+            print(logbook.stream)
 
     return population, logbook
diff --git a/deap/base.py b/deap/base.py
index b57b966..af5cd9d 100644
--- a/deap/base.py
+++ b/deap/base.py
@@ -66,7 +66,7 @@ class Toolbox(object):
         The following code block is an example of how the toolbox is used. ::
 
             >>> def func(a, b, c=3):
-            ...     print a, b, c
+            ...     print(a, b, c)
             ...
             >>> tools = Toolbox()
             >>> tools.register("myFunc", func, 2, c=4)
@@ -189,12 +189,12 @@ class Fitness(object):
             self.wvalues = tuple(map(mul, values, self.weights))
         except TypeError:
             _, _, traceback = sys.exc_info()
-            raise TypeError, ("Both weights and assigned values must be a "
+            raise TypeError(("Both weights and assigned values must be a "
                               "sequence of numbers when assigning to values of "
                               "%r. Currently assigning value(s) %r of %r to a "
                               "fitness with weights %s."
                               % (self.__class__, values, type(values),
-                                 self.weights)), traceback
+                                 self.weights))).with_traceback(traceback)
 
     def delValues(self):
         self.wvalues = ()
diff --git a/deap/benchmarks/movingpeaks.py b/deap/benchmarks/movingpeaks.py
index f0cfe2e..cbedce6 100644
--- a/deap/benchmarks/movingpeaks.py
+++ b/deap/benchmarks/movingpeaks.py
@@ -393,6 +393,6 @@ def diversity(population):
 
 if __name__ == "__main__":
     mpb = MovingPeaks(dim=2, npeaks=[1,1,10], number_severity=0.1)
-    print mpb.maximums()
+    print(mpb.maximums())
     mpb.changePeaks()
-    print mpb.maximums()
+    print(mpb.maximums())
diff --git a/deap/gp.py b/deap/gp.py
index 451a2da..26ca4e8 100644
--- a/deap/gp.py
+++ b/deap/gp.py
@@ -478,11 +478,11 @@ def compile(expr, pset):
         return eval(code, pset.context, {})
     except MemoryError:
         _, _, traceback = sys.exc_info()
-        raise MemoryError, ("DEAP : Error in tree evaluation :"
+        raise MemoryError("DEAP : Error in tree evaluation :"
                             " Python cannot evaluate a tree higher than 90. "
                             "To avoid this problem, you should use bloat control on your "
                             "operators. See the DEAP documentation for more information. "
-                            "DEAP will now abort."), traceback
+                            "DEAP will now abort.").with_traceback(traceback)
 
 
 def compileADF(expr, psets):
@@ -613,9 +613,9 @@ def generate(pset, min_, max_, condition, type_=None):
                 term = random.choice(pset.terminals[type_])
             except IndexError:
                 _, _, traceback = sys.exc_info()
-                raise IndexError, "The gp.generate function tried to add " \
+                raise IndexError("The gp.generate function tried to add " \
                                   "a terminal of type '%s', but there is " \
-                                  "none available." % (type_,), traceback
+                                  "none available." % (type_,)).with_traceback(traceback)
             if isclass(term):
                 term = term()
             expr.append(term)
@@ -624,9 +624,9 @@ def generate(pset, min_, max_, condition, type_=None):
                 prim = random.choice(pset.primitives[type_])
             except IndexError:
                 _, _, traceback = sys.exc_info()
-                raise IndexError, "The gp.generate function tried to add " \
+                raise IndexError("The gp.generate function tried to add " \
                                   "a primitive of type '%s', but there is " \
-                                  "none available." % (type_,), traceback
+                                  "none available." % (type_,)).with_traceback(traceback)
             expr.append(prim)
             for arg in reversed(prim.args):
                 stack.append((depth + 1, arg))
@@ -1058,7 +1058,7 @@ def harm(population, toolbox, cxpb, mutpb, ngen,
     record = stats.compile(population) if stats else {}
     logbook.record(gen=0, nevals=len(invalid_ind), **record)
     if verbose:
-        print logbook.stream
+        print(logbook.stream)
 
     # Begin the generational process
     for gen in range(1, ngen + 1):
@@ -1125,7 +1125,7 @@ def harm(population, toolbox, cxpb, mutpb, ngen,
         record = stats.compile(population) if stats else {}
         logbook.record(gen=gen, nevals=len(invalid_ind), **record)
         if verbose:
-            print logbook.stream
+            print(logbook.stream)
 
     return population, logbook
 
diff --git a/deap/tests/test_logbook.py b/deap/tests/test_logbook.py
index 7a7639e..3194ade 100644
--- a/deap/tests/test_logbook.py
+++ b/deap/tests/test_logbook.py
@@ -7,7 +7,7 @@ class LogbookTest(unittest.TestCase):
 
     def setUp(self):
         self.logbook = tools.Logbook()
-        print
+        print()
 
     def test_multi_chapters(self):
         self.logbook.record(gen=0, evals=100, fitness={'obj 1' : {'avg' : 1.0, 'max' : 10},
diff --git a/deap/tools/support.py b/deap/tools/support.py
index 3f4ac7e..7decd65 100644
--- a/deap/tools/support.py
+++ b/deap/tools/support.py
@@ -302,7 +302,7 @@ class Logbook(list):
             >>> # [...]
             >>> record = mstats.compile(population)
             >>> logbook.record(**record)
-            >>> print logbook
+            >>> print(logbook)
               fitness          length
             ------------    ------------
             max     mean    max     mean
@@ -388,11 +388,11 @@ class Logbook(list):
 
             >>> log = Logbook()
             >>> log.append({'gen' : 0})
-            >>> print log.stream  # doctest: +NORMALIZE_WHITESPACE
+            >>> print(log.stream)  # doctest: +NORMALIZE_WHITESPACE
             gen
             0
             >>> log.append({'gen' : 1})
-            >>> print log.stream  # doctest: +NORMALIZE_WHITESPACE
+            >>> print(log.stream)  # doctest: +NORMALIZE_WHITESPACE
             1
         """
         startindex, self.buffindex = self.buffindex, len(self)
diff --git a/doc/code/tutorials/part_3/3_next_step.py b/doc/code/tutorials/part_3/3_next_step.py
index ff59e08..356e96a 100644
--- a/doc/code/tutorials/part_3/3_next_step.py
+++ b/doc/code/tutorials/part_3/3_next_step.py
@@ -17,8 +17,8 @@ toolbox.register("individual", tools.initRepeat, creator.Individual,
 
 ind1 = toolbox.individual()
 
-print ind1               # [0.86..., 0.27..., 0.70..., 0.03..., 0.87...]
-print ind1.fitness.valid # False
+print(ind1)               # [0.86..., 0.27..., 0.70..., 0.03..., 0.87...]
+print(ind1.fitness.valid) # False
 
 ## 3.2 Evaluation
 def evaluate(individual):
@@ -28,16 +28,16 @@ def evaluate(individual):
     return a, 1. / b
 
 ind1.fitness.values = evaluate(ind1)
-print ind1.fitness.valid    # True
-print ind1.fitness          # (2.73, 0.2)
+print(ind1.fitness.valid)    # True
+print(ind1.fitness)          # (2.73, 0.2)
 
 ## 3.3 Mutation
 mutant = toolbox.clone(ind1)
 ind2, = tools.mutGaussian(mutant, mu=0.0, sigma=0.2, indpb=0.2)
 del mutant.fitness.values
 
-print ind2 is mutant    # True
-print mutant is ind1    # False
+print(ind2 is mutant)   # True
+print(mutant is ind1)    # False
 
 ## 3.4 Crossover
 child1, child2 = [toolbox.clone(ind) for ind in (ind1, ind2)]
@@ -47,7 +47,7 @@ del child2.fitness.values
 
 ## 3.5 Selection
 selected = tools.selBest([child1, child2], 2)
-print child1 in selected	# True
+print(child1 in selected)	# True
 
 ## 3.5 Note
 LAMBDA = 10
diff --git a/doc/code/tutorials/part_4/4_4_Using_Cpp_NSGA.py b/doc/code/tutorials/part_4/4_4_Using_Cpp_NSGA.py
index 44e387f..dfa8b49 100644
--- a/doc/code/tutorials/part_4/4_4_Using_Cpp_NSGA.py
+++ b/doc/code/tutorials/part_4/4_4_Using_Cpp_NSGA.py
@@ -91,8 +91,8 @@ def main():
     stats.update(population)
     
     # Begin the evolution
-    for g in xrange(NGEN):
-        print "-- Generation %i --" % g
+    for g in range(NGEN):
+        print("-- Generation %i --" % g)
         offspring = [toolbox.clone(ind) for ind in population]
     
         # Apply crossover and mutation
@@ -121,21 +121,21 @@ def main():
         for ind, fit in zip(invalid_ind, fitnesses):
             ind.fitness.values = fit
         
-        print "  Evaluated %i individuals" % len(invalid_ind)
+        print("  Evaluated %i individuals" % len(invalid_ind))
         
         population = toolbox.select(population+offspring, len(offspring))
         hof.update(population)
         stats.update(population)
 
-        print "  Min %s" % stats.Min[0][-1][0]
-        print "  Max %s" % stats.Max[0][-1][0]
-        print "  Avg %s" % stats.Avg[0][-1][0]
-        print "  Std %s" % stats.Std[0][-1][0]
+        print("  Min %s" % stats.Min[0][-1][0])
+        print("  Max %s" % stats.Max[0][-1][0])
+        print("  Avg %s" % stats.Avg[0][-1][0])
+        print("  Std %s" % stats.Std[0][-1][0])
 
     best_network = sn.SortingNetwork(INPUTS, hof[0])
-    print best_network
-    print best_network.draw()
-    print "%i errors, length %i, depth %i" % hof[0].fitness.values
+    print(best_network)
+    print(best_network.draw())
+    print("%i errors, length %i, depth %i" % hof[0].fitness.values)
     
     return population, stats, hof
 
diff --git a/doc/code/tutorials/part_4/4_5_home_made_eval_func.py b/doc/code/tutorials/part_4/4_5_home_made_eval_func.py
index 1646fff..af5145e 100644
--- a/doc/code/tutorials/part_4/4_5_home_made_eval_func.py
+++ b/doc/code/tutorials/part_4/4_5_home_made_eval_func.py
@@ -97,9 +97,9 @@ def main():
     stats.update(population)
     
     # Begin the evolution
-    for g in xrange(NGEN):
+    for g in range(NGEN):
         t1 = time.time()
-        print "-- Generation %i --" % g
+        print("-- Generation %i --" % g)
         offspring = [toolbox.clone(ind) for ind in population]
         t2 = time.time()
         # Apply crossover and mutation
@@ -128,14 +128,14 @@ def main():
         for ind, fit in zip(invalid_ind, fitnesses):
             ind.fitness.values = fit
         
-        print "  Evaluated %i individuals" % len(invalid_ind)
+        print("  Evaluated %i individuals" % len(invalid_ind))
         t5 = time.time()
         population = toolbox.select(population+offspring, len(offspring))
         t6 = time.time()
         #hof.update(population)
         stats.update(population)
         t7 = time.time()
-        print stats
+        print(stats)
         
         print("Times :")
         print("Clone : " + str(t2-t1) + " (" + str((t2-t1)/(t7-t1)) +"%)")
@@ -148,9 +148,9 @@ def main():
         
 
     best_network = sn.SortingNetwork(INPUTS, hof[0])
-    print best_network
-    print best_network.draw()
-    print "%i errors, length %i, depth %i" % hof[0].fitness.values
+    print(best_network)
+    print(best_network.draw())
+    print("%i errors, length %i, depth %i" % hof[0].fitness.values)
     
     return population, stats, hof
 
diff --git a/doc/tutorials/advanced/numpy.rst b/doc/tutorials/advanced/numpy.rst
index d2c45f2..2c2a901 100644
--- a/doc/tutorials/advanced/numpy.rst
+++ b/doc/tutorials/advanced/numpy.rst
@@ -86,7 +86,7 @@ This cannot be used as a condition
 ::
 
 	>>> if operator.eq(a, b):
-	...     print "Gosh!"
+	...     print("Gosh!")
 	... 
 	Traceback (most recent call last):
 	  File "<stdin>", line 1, in <module>
@@ -102,7 +102,7 @@ Now the condition can be computed and the hall-of-fame will be happy.
 ::
 
 	>>> if numpy.array_equal(a, b):
-	...     print "Yeah!"
+	...     print("Yeah!")
 	"Yeah!"
 
 
