I apologize if this is not the right place for this, but I happened to notice a difference between PyPy and cPython’s datetime – a different exception if bad input is passed to datetime.fromisoformat
.
I couldn’t see where to file an issue for PyPy, and I suspect that PyPy is using cPython’s plain Python version of datetime, so it may be a cPython code issue anyway.
This is tested with 3.9, as that’s what I have easy access to, and where I found the bug. Anyway, here you go:
PyPy:
Python 3.9.16 | packaged by conda-forge | (feeb267e, May 11 2023, 16:55:41)
[PyPy 7.3.11 with GCC Clang 15.0.7] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> import datetime
>>>> datetime.datetime.fromisoformat("2023")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/chris.barker/miniconda3/envs/pypy/lib/pypy3.9/datetime.py", line 1781, in fromisoformat
date_components = _parse_isoformat_date(dstr)
File "/Users/chris.barker/miniconda3/envs/pypy/lib/pypy3.9/datetime.py", line 274, in _parse_isoformat_date
if dtstr[4] != '-':
IndexError: string index out of range
cPython:
Python 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:42:20)
[Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.fromisoformat("2023")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid isoformat string: '2023'
If someone can point me to the problematic code, I could work on a PR.
In my case, I was catching the ValueError, so PyPy broke my code
Thanks,
-CHB