1. Michael Twomey
  2. pyiso8601
Issue #3 resolved

dates returned by parse_date do not support deepcopy

Michael Twomey
repo owner created an issue

Original: https://code.google.com/p/pyiso8601/issues/detail?id=20

Reported by fogathmann, Jun 13, 2012 What steps will reproduce the problem?

from iso8601 import parse_date d = parse_date('2012-06-13 11:06:47+02:00') from copy import deepcopy d_copy = deepcopy(d) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 328, in _reconstruct args = deepcopy(args, memo) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy y = copier(x, memo) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 237, in _deepcopy_tuple y.append(deepcopy(a, memo)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct y = callable(*args) TypeError: init() takes exactly 4 arguments (1 given)

What is the expected output? What do you see instead?

I would expect this to work :-) .

What version of the product are you using? On what operating system?

0.4.1 on OS-X Lion.

Please provide any additional information below.

The problem seems to be with the iso8601.iso8601.FixedOffset object. The reduce method (inherited from tzinfo) returns data that the _reconstruct function in the copy module is unable to digest.

Using this as reduce seems to work:

def __reduce__(self):
    hrs, secs = divmod(self.__offset.seconds, 3600)
    mins = int(secs / 60)
    return (FixedOffset, (hrs, mins, self.__name), {})

Cheers,

Oliver Sep 18, 2012 Delete comment #2 john@openlearning.com I should also point out this means you can't pickle objects with FixedOffsets which, in my opinion, makes this a high priority issue.

It's been fixed in this fork: https://github.com/OpenLearningNet/pyiso8601

Comments (1)

  1. Log in to comment