Skip to content

deepcopy of Duration does not include weeks #870

Open
@gareththackeray

Description

@gareththackeray
  • I am on the latest Pendulum version.

  • I have searched the issues of this repo and believe that this is not a dup

  • OS version and name: macOS

  • Pendulum version: 3.0.0

Issue

If a Duration has more than 7 days, deepcopy is wrong as there is no mention of weeks.

def test():
    d = pendulum.Duration(days=9)

    d1 = copy.deepcopy(d)

    assert d1.total_days() == 9

gives

>       assert d1.total_days() == 9
E       assert 2.0 == 9
E        +  where 2.0 = total_days()
E        +    where total_days = Duration(days=2).total_days

This is because there is no weeks=self.weeks in __deepcopy__:

def __deepcopy__(self, _: dict[int, Self]) -> Self:
return self.__class__(
days=self.remaining_days,
seconds=self.remaining_seconds,
microseconds=self.microseconds,
minutes=self.minutes,
hours=self.hours,
years=self.years,
months=self.months,
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions