C code shadows Python in standard library?

Dear all, sorry if this is a stupid question.

Whilst looking at the issue 81708 I noticed, that for the method datetime.timestamp() code is present both in Python datetime.py as well as in _datetimemodule.c

And it looks like C code shadows Python code and python code never runs.

Question: am I right or I got it totally wrong somewhere?

if I am correct, then what is the purpose of such design?

You may be interested in PEP 399 – Pure Python/C Accelerator Module Compatibility Requirements | peps.python.org :slight_smile:

4 Likes

OK, thanks! It definitely helps.

In practice, you’re likely using the C implementation:

$ python3
Python 3.10.7 (main, Sep  7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> import _datetime
>>> datetime.datetime is _datetime.datetime
True
3 Likes