Skip to content

Commit 5e75950

Browse files
committed
[Ruff fixes] Returns -> Return
1 parent 23da064 commit 5e75950

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

src/neat/neat.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ def mutate_weight(self) -> None:
162162
self.weight = max(self.weight, -1)
163163

164164
def __copy__(self) -> Connection:
165-
"""Returns a copy of self."""
165+
"""Return a copy of self."""
166166
return self.clone(self.from_node, self.to_node)
167167

168168
def clone(self, from_node: Node, to_node: Node) -> Connection:
169-
"""Returns a clone of self, but with potentially different from_node and to_node values."""
169+
"""Return a clone of self, but with potentially different from_node and to_node values."""
170170
clone = self.__class__(
171171
from_node,
172172
to_node,
@@ -177,7 +177,7 @@ def clone(self, from_node: Node, to_node: Node) -> Connection:
177177
return clone
178178

179179
def save(self) -> ConnectionSave:
180-
"""Returns a list containing important information about this connection."""
180+
"""Return a list containing important information about this connection."""
181181
return (
182182
self.from_node.number,
183183
self.to_node.number,
@@ -228,7 +228,7 @@ def matches(
228228
from_node: Node,
229229
to_node: Node,
230230
) -> bool:
231-
"""Returns True if genomes are the same."""
231+
"""Return True if genomes are the same."""
232232
if len(genome.genes) == len(self.innovation_numbers) and (
233233
from_node.number == self.from_node
234234
and to_node.number == self.to_node
@@ -243,7 +243,7 @@ def matches(
243243
return False
244244

245245
def clone(self) -> History:
246-
"""Returns a clone of self."""
246+
"""Return a clone of self."""
247247
return History(
248248
self.from_node,
249249
self.to_node,
@@ -252,7 +252,7 @@ def clone(self) -> History:
252252
)
253253

254254
def save(self) -> HistorySave:
255-
"""Returns a list of important information about this history object."""
255+
"""Return a list of important information about this history object."""
256256
return (
257257
self.from_node,
258258
self.to_node,
@@ -262,7 +262,7 @@ def save(self) -> HistorySave:
262262

263263

264264
def matching_gene(parent: Genome, innovation_number: int) -> int | None:
265-
"""Returns index to a gene matching the input innovation number in the input genome."""
265+
"""Return index to a gene matching the input innovation number in the input genome."""
266266
for idx, gene in enumerate(parent.genes):
267267
if gene.innovation_number == innovation_number:
268268
return idx
@@ -346,7 +346,7 @@ def get_innov_no(
346346
from_node: Node,
347347
to_node: Node,
348348
) -> int:
349-
"""Returns the innovation number for the new mutation."""
349+
"""Return the innovation number for the new mutation."""
350350
is_new: bool = True
351351
conn_innov_no: int = 0
352352
for innov in innovation_history:
@@ -430,7 +430,7 @@ def fully_connect(self, innovation_history: list[History]) -> None:
430430
self.connect_nodes()
431431

432432
def get_node(self, node_no: int) -> Node:
433-
"""Returns the node with a matching number, as sometimes self.nodes will not be in order."""
433+
"""Return the node with a matching number, as sometimes self.nodes will not be in order."""
434434
for node in self.nodes:
435435
if node.number == node_no:
436436
return node
@@ -474,7 +474,7 @@ def gen_network(self) -> None:
474474
self.network.append(node)
475475

476476
def fully_connected(self) -> bool:
477-
"""Returns whether the network is fully connected or not."""
477+
"""Return whether the network is fully connected or not."""
478478
max_conns = 0
479479
# Dictionary which stored the amount of nodes in each layer
480480
nodes_in_layers = {layer: 0 for layer in range(self.layers)}
@@ -498,7 +498,7 @@ def fully_connected(self) -> bool:
498498
return max_conns <= len(self.genes)
499499

500500
def random_conn_nodes_bad(self, rn_1: int, rn_2: int) -> bool:
501-
"""Returns True if the two given nodes connected to each other."""
501+
"""Return True if the two given nodes connected to each other."""
502502
if self.nodes[rn_1].layer == self.nodes[rn_2].layer:
503503
# if the nodes are in the same layer
504504
return True
@@ -722,7 +722,7 @@ def __copy__(self) -> Genome:
722722
clone = __copy__
723723

724724
def save(self) -> GenomeSave:
725-
"""Returns important information about this Genome Object."""
725+
"""Return important information about this Genome Object."""
726726
genes = [gene.save() for gene in self.genes]
727727
nodes = [node.save() for node in self.nodes]
728728
return (
@@ -737,7 +737,7 @@ def save(self) -> GenomeSave:
737737

738738
@classmethod
739739
def load(cls, data: GenomeSave) -> Genome:
740-
"""Returns a new Genome Object based on save data input."""
740+
"""Return a new Genome Object based on save data input."""
741741
self = cls(*data[:2], False)
742742
(
743743
self.inputs,
@@ -819,7 +819,7 @@ def think(self) -> None:
819819
self.decision = self.brain.feed_forward(self.vision)
820820

821821
def clone(self) -> BasePlayer:
822-
"""Returns a clone of self."""
822+
"""Return a clone of self."""
823823
clone = self.__class__()
824824
clone.brain = self.brain.clone()
825825
clone.fitness = float(self.fitness)
@@ -835,14 +835,14 @@ def calculate_fitness(self) -> None:
835835
self.fitness = random.randint(0, 10)
836836

837837
def crossover(self, parent: BasePlayer) -> BasePlayer:
838-
"""Returns a BasePlayer object by crossing over our brain and parent2's brain."""
838+
"""Return a BasePlayer object by crossing over our brain and parent2's brain."""
839839
child = self.__class__()
840840
child.brain = self.brain.crossover(parent.brain)
841841
child.brain.gen_network()
842842
return child
843843

844844
def save(self) -> PlayerSave:
845-
"""Returns a list containing important information about ourselves."""
845+
"""Return a list containing important information about ourselves."""
846846
return (
847847
self.brain.save(),
848848
self.gen,
@@ -853,7 +853,7 @@ def save(self) -> PlayerSave:
853853

854854
@classmethod
855855
def load(cls, data: PlayerSave) -> BasePlayer:
856-
"""Returns a BasePlayer Object with save data given."""
856+
"""Return a BasePlayer Object with save data given."""
857857
self = cls()
858858
brain, self.gen, self.dead, self.best_score, self.score = data
859859
self.genome_inputs, self.genome_outputs = brain[:2]
@@ -912,7 +912,7 @@ def __repr__(self) -> str:
912912

913913
@staticmethod
914914
def get_excess_disjoint(brain1: Genome, brain2: Genome) -> int | float:
915-
"""Returns the number of excess and disjoint genes."""
915+
"""Return the number of excess and disjoint genes."""
916916
matching = 0
917917
for gene1 in brain1.genes:
918918
for gene2 in brain2.genes:
@@ -924,7 +924,7 @@ def get_excess_disjoint(brain1: Genome, brain2: Genome) -> int | float:
924924

925925
@staticmethod
926926
def avg_w_diff(brain1: Genome, brain2: Genome) -> int | float:
927-
"""Returns the average weight difference between two brains."""
927+
"""Return the average weight difference between two brains."""
928928
if not brain1.genes or not brain2.genes:
929929
return 0
930930
matching = 0
@@ -940,7 +940,7 @@ def avg_w_diff(brain1: Genome, brain2: Genome) -> int | float:
940940
return 100 if not matching else total_diff / matching
941941

942942
def same_species(self, genome: Genome) -> bool:
943-
"""Returns if a genome is in this species."""
943+
"""Return if a genome is in this species."""
944944
excess_and_disjoint = self.get_excess_disjoint(genome, self.rep)
945945
avg_w_diff = self.avg_w_diff(genome, self.rep)
946946
large_genome_normalizer = max(len(genome.genes) - 20, 1)
@@ -1011,7 +1011,7 @@ def select_player(self) -> BasePlayer:
10111011
return self.players[0]
10121012

10131013
def give_me_baby(self, innovation_history: list[History]) -> BasePlayer:
1014-
"""Returns a baby from either random clone or crossover of bests."""
1014+
"""Return a baby from either random clone or crossover of bests."""
10151015
if random.randint(0, 3) == 0:
10161016
# 25% of the time there is no crossover and child is a clone of a semi-random player
10171017
baby = self.select_player().clone()
@@ -1033,7 +1033,7 @@ def cull(self) -> None:
10331033
self.players = self.players[int(len(self.players) / 2) :]
10341034

10351035
def clone(self) -> Species:
1036-
"""Returns a clone of self."""
1036+
"""Return a clone of self."""
10371037
clone = Species()
10381038
clone.players = [player.clone() for player in self.players]
10391039
clone.best_fitness = float(self.best_fitness)
@@ -1045,11 +1045,11 @@ def clone(self) -> Species:
10451045
return clone
10461046

10471047
def __copy__(self) -> Species:
1048-
"""Returns a copy of self."""
1048+
"""Return a copy of self."""
10491049
return self.clone()
10501050

10511051
def save(self) -> SpeciesSave:
1052-
"""Returns a list containing important information about this species."""
1052+
"""Return a list containing important information about this species."""
10531053
players = [player.save() for player in self.players]
10541054
champ = self.champ.save()
10551055
## rep = self.rep.save()
@@ -1128,7 +1128,7 @@ def update_alive(self) -> None:
11281128
self.global_best_score = player.score
11291129

11301130
def done(self) -> bool:
1131-
"""Returns True if all the players are dead. :(."""
1131+
"""Return True if all the players are dead. :(."""
11321132
return all(player.dead for player in self.players)
11331133

11341134
def setbest_player(self) -> None:
@@ -1209,7 +1209,7 @@ def kill_stale_species(self) -> None:
12091209
del self.species[i]
12101210

12111211
def get_avg_fitness_sum(self) -> int | float:
1212-
"""Returns the sum of the average fitness for each species."""
1212+
"""Return the sum of the average fitness for each species."""
12131213
return sum(s.average_fitness for s in self.species)
12141214

12151215
def kill_bad_species(self) -> None:
@@ -1281,7 +1281,7 @@ def natural_selection(self) -> None:
12811281
player.brain.gen_network()
12821282

12831283
def player_in_batch(self, player: BasePlayer, worlds: list[World]) -> bool:
1284-
"""Returns True if a player is in worlds...???."""
1284+
"""Return True if a player is in worlds...???."""
12851285
batch = int(self.batch_no * self.worlds_per_batch)
12861286
worldc = int(
12871287
min((self.batch_no + 1) * self.worlds_per_batch, len(worlds)),
@@ -1314,15 +1314,15 @@ def step_worlds_in_batch(
13141314
worlds[i].step(fps, arg2, arg3)
13151315

13161316
def batch_dead(self, worlds: list[World]) -> bool:
1317-
"""Returns True if all the players in a batch are dead. :(."""
1317+
"""Return True if all the players in a batch are dead. :(."""
13181318
batch = int(self.batch_no * self.worlds_per_batch)
13191319
world_count = int(
13201320
min((self.batch_no + 1) * self.worlds_per_batch, len(worlds)),
13211321
)
13221322
return all(self.players[i].dead for i in range(batch, world_count))
13231323

13241324
def clone(self) -> Population:
1325-
"""Returns a clone of self."""
1325+
"""Return a clone of self."""
13261326
clone = Population(len(self.players))
13271327
clone.players = [player.clone() for player in self.players]
13281328
clone.best_player = self.best_player.clone()
@@ -1337,11 +1337,11 @@ def clone(self) -> Population:
13371337
return clone
13381338

13391339
def __copy__(self) -> Population:
1340-
"""Returns a copy of self."""
1340+
"""Return a copy of self."""
13411341
return self.clone()
13421342

13431343
def save(self) -> PopulationSave:
1344-
"""Returns a list containing all important data."""
1344+
"""Return a list containing all important data."""
13451345
players = [player.save() for player in self.players]
13461346
bestp = self.best_player.save()
13471347
innoh = [innohist.save() for innohist in self.innovation_history]
@@ -1360,7 +1360,7 @@ def save(self) -> PopulationSave:
13601360

13611361
@classmethod
13621362
def load(cls, data: PopulationSave) -> Population:
1363-
"""Returns Population Object using save data."""
1363+
"""Return Population Object using save data."""
13641364
self = cls(len(data[0]), False)
13651365
(
13661366
players,

src/neat/vector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ def normalized(self) -> Self:
7575
return self / self.magnitude()
7676

7777
def heading_radians(self) -> float:
78-
"""Returns the arc tangent (measured in radians) of self.y/self.x."""
78+
"""Return the arc tangent (measured in radians) of self.y/self.x."""
7979
return math.atan2(self.y, self.x)
8080

8181
def heading(self) -> float:
82-
"""Returns the arc tangent (measured in degrees) of self.y/self.x.
82+
"""Return the arc tangent (measured in degrees) of self.y/self.x.
8383
8484
Angle is measured from the positive X axis counterclockwise.
8585
"""
8686
return math.degrees(self.heading_radians())
8787

8888
def rotate_radians(self, radians: float) -> Self:
89-
"""Returns a new vector by rotating self around (0, 0) by radians."""
89+
"""Return a new vector by rotating self around (0, 0) by radians."""
9090
new_heading = self.heading_radians() + radians
9191
return self.from_radians(new_heading, self.magnitude())
9292

9393
def rotate(self, degrees: float) -> Self:
94-
"""Returns a new vector by rotating self around (0, 0) by degrees.
94+
"""Return a new vector by rotating self around (0, 0) by degrees.
9595
9696
Angle is measured from the positive X axis counterclockwise.
9797
"""

0 commit comments

Comments
 (0)