| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ Pending removal in Python 3.20 | |||
| 7 | 7 | ||
| 8 | 8 | - :mod:`argparse` | |
| 9 | 9 | - :mod:`csv` | |
| 10 | + - :mod:`ctypes` | ||
| 10 | 11 | - :mod:`!ctypes.macholib` | |
| 11 | 12 | - :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead) | |
| 12 | 13 | - :mod:`http.server` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1032,6 +1032,7 @@ New deprecations | |||
| 1032 | 1032 | ||
| 1033 | 1033 | - :mod:`argparse` | |
| 1034 | 1034 | - :mod:`csv` | |
| 1035 | + - :mod:`ctypes` | ||
| 1035 | 1036 | - :mod:`!ctypes.macholib` | |
| 1036 | 1037 | - :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead) | |
| 1037 | 1038 | - :mod:`http.server` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,22 +5,16 @@ | |||
| 5 | 5 | import sysconfig as _sysconfig | |
| 6 | 6 | import types as _types | |
| 7 | 7 | ||
| 8 | - __version__ = "1.1.0" | ||
| 9 | - | ||
| 10 | 8 | from _ctypes import Union, Structure, Array | |
| 11 | 9 | from _ctypes import _Pointer | |
| 12 | 10 | from _ctypes import CFuncPtr as _CFuncPtr | |
| 13 | - from _ctypes import __version__ as _ctypes_version | ||
| 14 | 11 | from _ctypes import RTLD_LOCAL, RTLD_GLOBAL | |
| 15 | 12 | from _ctypes import ArgumentError | |
| 16 | 13 | from _ctypes import SIZEOF_TIME_T | |
| 17 | 14 | from _ctypes import CField | |
| 18 | 15 | ||
| 19 | 16 | from struct import calcsize as _calcsize | |
| 20 | 17 | ||
| 21 | - if __version__ != _ctypes_version: | ||
| 22 | - raise Exception("Version number mismatch", __version__, _ctypes_version) | ||
| 23 | - | ||
| 24 | 18 | if _os.name == "nt": | |
| 25 | 19 | from _ctypes import COMError, CopyComPointer, FormatError | |
| 26 | 20 | ||
@@ -673,3 +667,12 @@ def DllCanUnloadNow(): | |||
| 673 | 667 | raise SystemError(f"Unexpected sizeof(time_t): {SIZEOF_TIME_T=}") | |
| 674 | 668 | ||
| 675 | 669 | _reset_cache() | |
| 670 | + | ||
| 671 | + | ||
| 672 | + def __getattr__(name): | ||
| 673 | + if name == "__version__": | ||
| 674 | + from warnings import _deprecated | ||
| 675 | + | ||
| 676 | + _deprecated("__version__", remove=(3, 20)) | ||
| 677 | + return "1.1.0" # Do not change | ||
| 678 | + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,27 @@ | |||
| 1 | 1 | import os | |
| 2 | + import unittest | ||
| 2 | 3 | from test import support | |
| 3 | 4 | from test.support import import_helper | |
| 4 | 5 | ||
| 5 | 6 | ||
| 6 | 7 | # skip tests if the _ctypes extension was not built | |
| 7 | 8 | import_helper.import_module('ctypes') | |
| 8 | 9 | ||
| 10 | + | ||
| 11 | + class TestModule(unittest.TestCase): | ||
| 12 | + def test_deprecated__version__(self): | ||
| 13 | + import ctypes | ||
| 14 | + import _ctypes | ||
| 15 | + | ||
| 16 | + for mod in (ctypes, _ctypes): | ||
| 17 | + with self.subTest(mod=mod): | ||
| 18 | + with self.assertWarnsRegex( | ||
| 19 | + DeprecationWarning, | ||
| 20 | + "'__version__' is deprecated and slated for removal in Python 3.20", | ||
| 21 | + ) as cm: | ||
| 22 | + getattr(mod, "__version__") | ||
| 23 | + self.assertEqual(cm.filename, __file__) | ||
| 24 | + | ||
| 25 | + | ||
| 9 | 26 | def load_tests(*args): | |
| 10 | 27 | return support.load_package_tests(os.path.dirname(__file__), *args) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Deprecate ``__version__`` from :mod:`ctypes`. Patch by Hugo van Kemenade. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6334,7 +6334,6 @@ _ctypes_add_objects(PyObject *mod) | |||
| 6334 | 6334 | MOD_ADD("FUNCFLAG_USE_ERRNO", PyLong_FromLong(FUNCFLAG_USE_ERRNO)); | |
| 6335 | 6335 | MOD_ADD("FUNCFLAG_USE_LASTERROR", PyLong_FromLong(FUNCFLAG_USE_LASTERROR)); | |
| 6336 | 6336 | MOD_ADD("FUNCFLAG_PYTHONAPI", PyLong_FromLong(FUNCFLAG_PYTHONAPI)); | |
| 6337 | - MOD_ADD("__version__", PyUnicode_FromString("1.1.0")); | ||
| 6338 | 6337 | ||
| 6339 | 6338 | MOD_ADD("_memmove_addr", PyLong_FromVoidPtr(memmove)); | |
| 6340 | 6339 | MOD_ADD("_memset_addr", PyLong_FromVoidPtr(memset)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1990,8 +1990,32 @@ buffer_info(PyObject *self, PyObject *arg) | |||
| 1990 | 1990 | } | |
| 1991 | 1991 | ||
| 1992 | 1992 | ||
| 1993 | + static PyObject * | ||
| 1994 | + _ctypes_getattr(PyObject *Py_UNUSED(self), PyObject *args) | ||
| 1995 | + { | ||
| 1996 | + PyObject *name; | ||
| 1997 | + if (!PyArg_UnpackTuple(args, "__getattr__", 1, 1, &name)) { | ||
| 1998 | + return NULL; | ||
| 1999 | + } | ||
| 2000 | + | ||
| 2001 | + if (PyUnicode_Check(name) && PyUnicode_EqualToUTF8(name, "__version__")) { | ||
| 2002 | + if (PyErr_WarnEx(PyExc_DeprecationWarning, | ||
| 2003 | + "'__version__' is deprecated and slated for " | ||
| 2004 | + "removal in Python 3.20", | ||
| 2005 | + 1) < 0) { | ||
| 2006 | + return NULL; | ||
| 2007 | + } | ||
| 2008 | + return PyUnicode_FromString("1.1.0"); // Do not change | ||
| 2009 | + } | ||
| 2010 | + | ||
| 2011 | + PyErr_Format(PyExc_AttributeError, | ||
| 2012 | + "module '_ctypes' has no attribute %R", name); | ||
| 2013 | + return NULL; | ||
| 2014 | + } | ||
| 2015 | + | ||
| 1993 | 2016 | ||
| 1994 | 2017 | PyMethodDef _ctypes_module_methods[] = { | |
| 2018 | + {"__getattr__", _ctypes_getattr, METH_VARARGS}, | ||
| 1995 | 2019 | {"get_errno", get_errno, METH_NOARGS}, | |
| 1996 | 2020 | {"set_errno", set_errno, METH_VARARGS}, | |
| 1997 | 2021 | {"_unpickle", unpickle, METH_VARARGS }, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments