Skip to content

Commit

Permalink
feat: avoid copies when constructing self
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Feb 29, 2024
1 parent 7d15b1d commit 9652c89
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/vector/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))


Expand Down

0 comments on commit 9652c89

Please sign in to comment.