[Pyobjc-dev] Python 3 + pyobjc_unicode + strptime = crash
Brought to you by:
ronaldoussoren
From: Virgil D. <hs...@ha...> - 2010-09-08 10:03:25
|
Hi, (Sorry for not submitting it to the tracker, I don't remember my old SF login, I dislike SF and I want to avoid dealing with it.) I uncovered a bug today. Under Python 3, when using a pyobjc_unicode with strptime, I get a this crash: Traceback (most recent call last): File "pyobjc_strptime_bug.py", line 6, in <module> print(datetime.strptime(s, '%Y-%m-%d')) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/_strptime.py", line 335, in _strptime data_string[found.end():]) ValueError: unconverted data remains: o I created a script that reproduces the bug: from Foundation import NSString s = NSString.alloc().initWithString_('2010-09-08') print(type(s)) # Very interesting, the bug only shows up if datetime is imported here instead of at the top from datetime import datetime print(datetime.strptime(s, '%Y-%m-%d')) As the comment says in the script, the interesting thing is that the crash only happens if the datetime import happens after the allocation of the NSString. If you move the import at the top, the crash doesn't happen anymore and the function behaves as expected. For now, the workaround I do in my project is to explicitly cast my input to str() and it works. Virgil Dupras |