From d3b08165c3a1be789271f5095b8b78525cd440ca Mon Sep 17 00:00:00 2001 From: SeaTechRC <153106523+SeaTechRC@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:07:25 +0200 Subject: [PATCH] Removed potential mutable default argument issues. --- field_friend/automations/field_provider.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/field_friend/automations/field_provider.py b/field_friend/automations/field_provider.py index ef724d75..17d6b5bb 100644 --- a/field_friend/automations/field_provider.py +++ b/field_friend/automations/field_provider.py @@ -53,7 +53,9 @@ def invalidate(self) -> None: self.request_backup() self.FIELDS_CHANGED.emit() - def create_field(self, points: list[GeoPoint] = []) -> Field: + def create_field(self, points: list[GeoPoint] | None = None) -> Field: + if points is None: + points = [] new_id = str(uuid.uuid4()) field = Field(id=f'{new_id}', name=f'field_{len(self.fields)+1}', points=points) self.fields.append(field) @@ -70,7 +72,9 @@ def clear_fields(self) -> None: self.FIELDS_CHANGED.emit() self.invalidate() - def create_obstacle(self, field: Field, points: list[GeoPoint] = []) -> FieldObstacle: + def create_obstacle(self, field: Field, points: list[GeoPoint] | None = None) -> FieldObstacle: + if points is None: + points = [] obstacle = FieldObstacle(id=f'{str(uuid.uuid4())}', name=f'obstacle_{len(field.obstacles)+1}', points=points) field.obstacles.append(obstacle) self.invalidate() @@ -80,7 +84,9 @@ def remove_obstacle(self, field: Field, obstacle: FieldObstacle) -> None: field.obstacles.remove(obstacle) self.invalidate() - def create_row(self, field: Field, points: list[GeoPoint] = []) -> Row: + def create_row(self, field: Field, points: list[GeoPoint] | None = None) -> Row: + if points is None: + points = [] row = Row(id=f'{str(uuid.uuid4())}', name=f'row_{len(field.rows)+1}', points=points) field.rows.append(row) self.invalidate()