Skip to content

TimezoneInfo cannot be deepcopied #133

@AndreasBackx

Description

@AndreasBackx

When converting a Pendulum class to a datetime object, it still keeps the tzinfo of the type TimeZoneInfo of the Pendulum object. Then when trying to deepcopy that, it raises the TypeError seen below.

from copy import deepcopy

import pendulum

pd = pendulum.parse('2017-07-11 17:19:18.686028+02:00')
dt = pd._datetime

deepcopy(pd)
deepcopy(dt)  # TypeError raised here.

Traceback

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/andreas/.pyenv/versions/project/lib/python3.5/copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/home/andreas/.pyenv/versions/project/lib/python3.5/copy.py", line 291, in _reconstruct
    args = deepcopy(args, memo)
  File "/home/andreas/.pyenv/versions/project/lib/python3.5/copy.py", line 155, in deepcopy
    y = copier(x, memo)
  File "/home/andreas/.pyenv/versions/project/lib/python3.5/copy.py", line 223, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/home/andreas/.pyenv/versions/project/lib/python3.5/copy.py", line 223, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/home/andreas/.pyenv/versions/project/lib/python3.5/copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/home/andreas/.pyenv/versions/project/lib/python3.5/copy.py", line 292, in _reconstruct
    y = callable(*args)
TypeError: __init__() missing 5 required positional arguments: 'tz', 'utc_offset', 'is_dst', 'dst', and 'abbrev'

I found this bug because of another issue I made: romgar/django-dirtyfields#101.

This was tested on Pendulum 1.2.4 and Python 3.5.3.

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