From 9652c89d5acde3f3f0be15c2b0522f22f8863581 Mon Sep 17 00:00:00 2001 From: nstarman Date: Thu, 29 Feb 2024 11:57:46 -0500 Subject: [PATCH] feat: avoid copies when constructing self Signed-off-by: nstarman --- src/vector/_base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vector/_base.py b/src/vector/_base.py index ebfa930e..da87b9c8 100644 --- a/src/vector/_base.py +++ b/src/vector/_base.py @@ -582,6 +582,10 @@ def constructor( # noqa: D417 msg = f"Cannot construct {cls} from {type(obj)}." raise TypeError(msg) + # avoid copying if the types are the same + if type(obj) is cls: + return obj + return cls(**dict(dataclass_items(obj)))