Cleaner structure repr without making assumptions on usage

This commit is contained in:
SimpleArt
2020-12-23 11:41:27 -05:00
parent adab92216f
commit f5244e3cc9
3 changed files with 9 additions and 6 deletions

View File

@ -163,12 +163,13 @@ class Chromosome:
""" """
Allows the user to use Allows the user to use
chromosome_string = repr(chromosome) chromosome_string = repr(chromosome)
chromosome = eval(chromosome_string) chromosome_data = eval(chromosome_string)
chromosome = ga.make_chromosome(chromosome_data)
to get a backend representation of the chromosome to get a backend representation of the chromosome
which can be evaluated directly as code to create which can be evaluated directly as code to create
the chromosome. the chromosome.
""" """
return f"EasyGA.make_chromosome({repr(self.gene_list)})" return repr(self.gene_list)
def __str__(self): def __str__(self):

View File

@ -29,10 +29,11 @@ class Gene:
""" """
Allows the user to use Allows the user to use
gene_string = repr(gene) gene_string = repr(gene)
gene = eval(gene_string) gene_data = eval(gene_string)
gene = ga.make_gene(gene_data)
to get a backend representation of the gene. to get a backend representation of the gene.
""" """
return f"EasyGA.make_gene({repr(self.value)})" return repr(self.value)
def __str__(self): def __str__(self):

View File

@ -188,12 +188,13 @@ class Population:
""" """
Allows the user to use Allows the user to use
population_string = repr(population) population_string = repr(population)
population = eval(population_string) population_data = eval(population_string)
population = ga.make_population(population_data)
to get a backend representation of the population to get a backend representation of the population
which can be evaluated directly as code to create which can be evaluated directly as code to create
the population. the population.
""" """
return f"EasyGA.make_population({repr(self.chromosome_list)})" return repr(self.chromosome_list)
def __str__(self): def __str__(self):