From e4fe2b0fa83c64605ab7ed77dbc2c3cc9ed6f446 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Tue, 14 Jan 2025 18:08:05 +0100 Subject: [PATCH] removed call to __init__ in __new__ --- CHANGELOG.md | 2 ++ src/compas/geometry/curves/line.py | 4 +--- tests/compas/geometry/test_curves_line.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a659a2ac91..86d7551da2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +* Fixed cannot copy `Line` using `deepcopy`. + ### Removed diff --git a/src/compas/geometry/curves/line.py b/src/compas/geometry/curves/line.py index f715b47e0a10..b17799987db6 100644 --- a/src/compas/geometry/curves/line.py +++ b/src/compas/geometry/curves/line.py @@ -69,9 +69,7 @@ class Line(Curve): # overwriting the __new__ method is necessary # to avoid triggering the plugin mechanism of the base curve class def __new__(cls, *args, **kwargs): - curve = object.__new__(cls) - curve.__init__(*args, **kwargs) - return curve + return object.__new__(cls) DATASCHEMA = { "type": "object", diff --git a/tests/compas/geometry/test_curves_line.py b/tests/compas/geometry/test_curves_line.py index d049ec091a73..fbc272b2fa4d 100644 --- a/tests/compas/geometry/test_curves_line.py +++ b/tests/compas/geometry/test_curves_line.py @@ -1,3 +1,4 @@ +from copy import deepcopy import pytest import json import compas @@ -282,3 +283,17 @@ def test_line_flip(p1, p2): flipped_line = Line(p1, p2).flipped() assert TOL.is_zero(distance_point_point(flipped_line.start, p2)) assert TOL.is_zero(distance_point_point(flipped_line.end, p1)) + + +def test_line_copy_deepcopy(): + line = Line([0, 0, 0], [1, 0, 0]) + + line_copy = line.copy() + + assert line is not line_copy + assert line == line_copy + + line_deepcopy = deepcopy(line) + + assert line is not line_deepcopy + assert line == line_deepcopy