metomi/isodatetime

isodatetime lib triggers a known bug in Python 2.6.2

hjoliver opened this issue · 5 comments

$ cylc cyclepoint 20140808T00
Traceback (most recent call last):
  File "/gpfs_oper/filesets/oper/admin/um_fcm/cylc/cylc-6.0.1-alpha1/bin/cylc-cycle-point", line 195, in <module>
    cycle_point_string, dump_as_parsed=(template is None))
  File "/gpfs_oper/filesets/oper/admin/um_fcm/cylc/cylc-6.0.1-alpha1/lib/isodatetime/parsers.py", line 242, in parse
    truncated_dump_format=dump_format)
  File "/gpfs_oper/filesets/oper/admin/um_fcm/cylc/cylc-6.0.1-alpha1/lib/isodatetime/parsers.py", line 310, in _create_timepoint_from_info
    return data.TimePoint(**info)
TypeError: __init__() keywords must be strings

Use of unicode strings here is triggering this bug in Python 2.6.2: http://bugs.python.org/issue2646

@benfitzpatrick - this is not a bug in isodatetime as such, but Python 2.6.2 is still commonly used (one of our major HPC hosts at NIWA, for instance). Would it be difficult to provide a workaround?

Printing the info dict shows:

{'truncated_dump_format': u'CCYYMMDDThh',
u'month_of_year': 8,
'dump_format': u'CCYYMMDDThh',
'year': 2014,
'time_zone_minute': 0.0,
u'day_of_month': 8,
u'hour_of_day': 0.0,
'time_zone_hour': 0.0}

there's an odd mix of unicode and non-unicode strings for keys and values - is that intentional?

A one-off conversion to str at isodatetime/parsers.py:310 might be sufficient (I'm testing this) as the machine is only a task host.

Unicode keys are definitely not intentional. The unicode values are a good thing, I think, as
people may want lots of unusual things in their dump format (e.g. maybe CCYY年MM月DD日 -
Chinese date format that uses year, month, day unit characters).

@benfitzpatrick - my aforementioned quick fix works, but given that the unicode keys are not intentional, can you fix that? It's not immediately obvious to me where they are coming from.

I'm bumping this issue to next-release, as it would be a difficult one for anyone unfortunate enough to be running the wrong version of Python.

I'm bumping this issue to next-release

Sorry - I briefly forgot this wasn't a cylc issue - reassign to milestones as you wish!!