Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ However, starting in version 2, `backports.datetime_fromisoformat` will apply it

## Unreleased

* Nil.
* Silenced errors when compiling against Python 3.13
* Note: `backports.datetime_fromisoformat` does nothing when used against Python 3.11+. Use `backports-datetime-fromisoformat; python_version < '3.11'` in your dependency list to avoid even downloading it in modern Pythons

## Version 2.0.2

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Quick Start

.. code:: bash

pip install backports-datetime-fromisoformat
pip install "backports-datetime-fromisoformat; python_version < '3.11'"

**Usage:**

Expand Down
26 changes: 26 additions & 0 deletions backports/datetime_fromisoformat/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* 037e9125527d4a55af566f161c96a61b3c3fd998)
* It was then refreshed using the Python 3.11 contents present at
* 27d8dc2c9d3de886a884f79f0621d4586c0e0f7a
* Finally, the `_PyUnicode_Copy` implementation was copied from
* c8749b578324ad4089c8d014d9136bc42b065343
*
* Since then, I have:
* - torn out all the functionality that doesn't matter to
* `backports.datetime_fromisoformat`
* - switched calls to datetime creation to use the versions found in
* `PyDateTimeAPI`
* - made minor changes to make it compilable for older versions of Python.
* - Including in-lining a copy of _PyUnicode_Copy
*
* Below is a copy of the Python 3.11 code license
* (from https://docs.python.org/3/license.html):
Expand Down Expand Up @@ -749,6 +752,29 @@ time_fromisoformat(PyObject *tstr)
return NULL;
}

PyObject *
_PyUnicode_Copy(PyObject *unicode)
{
Py_ssize_t length;
PyObject *copy;

if (!PyUnicode_Check(unicode)) {
PyErr_BadInternalCall();
return NULL;
}

length = PyUnicode_GET_LENGTH(unicode);
copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
if (!copy)
return NULL;
assert(PyUnicode_KIND(copy) == PyUnicode_KIND(unicode));

memcpy(PyUnicode_DATA(copy), PyUnicode_DATA(unicode),
length * PyUnicode_KIND(unicode));
assert(_PyUnicode_CheckConsistency(copy, 1));
return copy;
}

static PyObject *
_sanitize_isoformat_str(PyObject *dtstr)
{
Expand Down
Loading