You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PyDateTime_IMPORT macro doesn't do error checking and isn't documented to return anything, so I think to fix this there would need to be a new function or macro that can fail that people can migrate too.
[build-system]
requires = [
"meson>=0.63.0",
"meson-python",
]
build-backend = "mesonpy"
[project]
name = "test_datetime"
requires-python = ">=3.9.0"
version = "0.0.1"%
and then if I put a file named datetime.py somewhere in my import path (e.g. next to the C extension), I get the following error about an unhandled exception:
$ touch datetime.py
$ python
Python 3.13.0 experimental free-threading build (main, Oct 10 2024, 10:28:54) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import test_datetime
AttributeError: module 'datetime' has no attribute 'datetime_CAPI' (consider renaming '/Users/goldbaum/Documents/test-datetime/build/datetime.py' since it has the same name as the standard library module named 'datetime' and the import system gives it precedence)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
import test_datetime
SystemError: initialization of test_datetime raised unreported exception
It looks like the same trick doesn't work on CPython itself if I create a datetime.py file and do import zoneinfo, it's only problematic for extensions.
The text was updated successfully, but these errors were encountered:
The
PyDateTime_IMPORT
macro doesn't do error checking and isn't documented to return anything, so I think to fix this there would need to be a new function or macro that can fail that people can migrate too.c.f. python/cpython#122184 (comment)
The
PyDateTime_IMPORT
macro is defined like this:This is problematic because
PyCapsule_Import
can fail. And indeed if I create a C extension with the following content:build it with the following
meson.build
:and
pyproject.toml
:and then if I put a file named
datetime.py
somewhere in my import path (e.g. next to the C extension), I get the following error about an unhandled exception:It looks like the same trick doesn't work on CPython itself if I create a
datetime.py
file and doimport zoneinfo
, it's only problematic for extensions.The text was updated successfully, but these errors were encountered: