Skip to content

Commit 22d4856

Browse files
committed
Rename to PyImport_ImportModuleAttr()
1 parent 4fc2e10 commit 22d4856

34 files changed

+85
-85
lines changed

Doc/c-api/import.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ Importing Modules
327327
initialization.
328328
329329
330-
.. c:function:: PyObject* PyImport_GetModuleAttr(PyObject *mod_name, PyObject *attr_name)
330+
.. c:function:: PyObject* PyImport_ImportModuleAttr(PyObject *mod_name, PyObject *attr_name)
331331
332332
Import the module *mod_name* and get its attribute *attr_name*.
333333
@@ -340,9 +340,9 @@ Importing Modules
340340
341341
.. versionadded:: 3.14
342342
343-
.. c:function:: PyObject* PyImport_GetModuleAttrString(const char *mod_name, const char *attr_name)
343+
.. c:function:: PyObject* PyImport_ImportModuleAttrString(const char *mod_name, const char *attr_name)
344344
345-
Similar to :c:func:`PyImport_GetModuleAttr`, but names are UTF-8 encoded
345+
Similar to :c:func:`PyImport_ImportModuleAttr`, but names are UTF-8 encoded
346346
strings instead of Python :class:`str` objects.
347347
348348
.. versionadded:: 3.14

Doc/data/refcounts.dat

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,10 +3053,10 @@ _Py_c_sum:Py_complex:::
30533053
_Py_c_sum:Py_complex:left::
30543054
_Py_c_sum:Py_complex:right::
30553055

3056-
PyImport_GetModuleAttr:PyObject*::+1:
3057-
PyImport_GetModuleAttr:PyObject*:mod_name:0:
3058-
PyImport_GetModuleAttr:PyObject*:attr_name:0:
3056+
PyImport_ImportModuleAttr:PyObject*::+1:
3057+
PyImport_ImportModuleAttr:PyObject*:mod_name:0:
3058+
PyImport_ImportModuleAttr:PyObject*:attr_name:0:
30593059

3060-
PyImport_GetModuleAttrString:PyObject*::+1:
3061-
PyImport_GetModuleAttrString:const char *:mod_name::
3062-
PyImport_GetModuleAttrString:const char *:attr_name::
3060+
PyImport_ImportModuleAttrString:PyObject*::+1:
3061+
PyImport_ImportModuleAttrString:const char *:mod_name::
3062+
PyImport_ImportModuleAttrString:const char *:attr_name::

Doc/whatsnew/3.14.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,8 @@ New features
13011301
bit-packing Python version numbers.
13021302
(Contributed by Petr Viktorin in :gh:`128629`.)
13031303

1304-
* Add :c:func:`PyImport_GetModuleAttr` and
1305-
:c:func:`PyImport_GetModuleAttrString` helper functions to import a module
1304+
* Add :c:func:`PyImport_ImportModuleAttr` and
1305+
:c:func:`PyImport_ImportModuleAttrString` helper functions to import a module
13061306
and get an attribute of the module.
13071307
(Contributed by Victor Stinner in :gh:`128911`.)
13081308

Include/cpython/import.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ struct _frozen {
2424

2525
PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules;
2626

27-
PyAPI_FUNC(PyObject*) PyImport_GetModuleAttr(
27+
PyAPI_FUNC(PyObject*) PyImport_ImportModuleAttr(
2828
PyObject *mod_name,
2929
PyObject *attr_name);
30-
PyAPI_FUNC(PyObject*) PyImport_GetModuleAttrString(
30+
PyAPI_FUNC(PyObject*) PyImport_ImportModuleAttrString(
3131
const char *mod_name,
3232
const char *attr_name);

Lib/test/test_capi/test_import.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -318,58 +318,58 @@ def test_executecodemoduleobject(self):
318318
# CRASHES execute_code_func(NULL, code, NULL, NULL)
319319
# CRASHES execute_code_func(name, NULL, NULL, NULL)
320320

321-
def check_getmoduleattr(self, getmoduleattr):
322-
self.assertIs(getmoduleattr('sys', 'argv'), sys.argv)
323-
self.assertIs(getmoduleattr('types', 'ModuleType'), types.ModuleType)
321+
def check_importmoduleattr(self, importmoduleattr):
322+
self.assertIs(importmoduleattr('sys', 'argv'), sys.argv)
323+
self.assertIs(importmoduleattr('types', 'ModuleType'), types.ModuleType)
324324

325325
# module name containing a dot
326-
attr = getmoduleattr('email.message', 'Message')
326+
attr = importmoduleattr('email.message', 'Message')
327327
from email.message import Message
328328
self.assertIs(attr, Message)
329329

330330
with self.assertRaises(ImportError):
331331
# nonexistent module
332-
getmoduleattr('nonexistentmodule', 'attr')
332+
importmoduleattr('nonexistentmodule', 'attr')
333333
with self.assertRaises(AttributeError):
334334
# nonexistent attribute
335-
getmoduleattr('sys', 'nonexistentattr')
335+
importmoduleattr('sys', 'nonexistentattr')
336336
with self.assertRaises(AttributeError):
337337
# attribute name containing a dot
338-
getmoduleattr('sys', 'implementation.name')
338+
importmoduleattr('sys', 'implementation.name')
339339

340-
def test_getmoduleattr(self):
341-
# Test PyImport_GetModuleAttr()
342-
getmoduleattr = _testcapi.PyImport_GetModuleAttr
343-
self.check_getmoduleattr(getmoduleattr)
340+
def test_importmoduleattr(self):
341+
# Test PyImport_ImportModuleAttr()
342+
importmoduleattr = _testcapi.PyImport_ImportModuleAttr
343+
self.check_importmoduleattr(importmoduleattr)
344344

345345
# Invalid module name type
346346
for mod_name in (object(), 123, b'bytes'):
347347
with self.subTest(mod_name=mod_name):
348348
with self.assertRaises(TypeError):
349-
getmoduleattr(mod_name, "attr")
349+
importmoduleattr(mod_name, "attr")
350350

351351
# Invalid attribute name type
352352
for attr_name in (object(), 123, b'bytes'):
353353
with self.subTest(attr_name=attr_name):
354354
with self.assertRaises(TypeError):
355-
getmoduleattr("sys", attr_name)
355+
importmoduleattr("sys", attr_name)
356356

357357
with self.assertRaises(SystemError):
358-
getmoduleattr(NULL, "argv")
359-
# CRASHES getmoduleattr("sys", NULL)
358+
importmoduleattr(NULL, "argv")
359+
# CRASHES importmoduleattr("sys", NULL)
360360

361-
def test_getmoduleattrstring(self):
362-
# Test PyImport_GetModuleAttrString()
363-
getmoduleattr = _testcapi.PyImport_GetModuleAttrString
364-
self.check_getmoduleattr(getmoduleattr)
361+
def test_importmoduleattrstring(self):
362+
# Test PyImport_ImportModuleAttrString()
363+
importmoduleattr = _testcapi.PyImport_ImportModuleAttrString
364+
self.check_importmoduleattr(importmoduleattr)
365365

366366
with self.assertRaises(UnicodeDecodeError):
367-
getmoduleattr(b"sys\xff", "argv")
367+
importmoduleattr(b"sys\xff", "argv")
368368
with self.assertRaises(UnicodeDecodeError):
369-
getmoduleattr("sys", b"argv\xff")
369+
importmoduleattr("sys", b"argv\xff")
370370

371-
# CRASHES getmoduleattr(NULL, "argv")
372-
# CRASHES getmoduleattr("sys", NULL)
371+
# CRASHES importmoduleattr(NULL, "argv")
372+
# CRASHES importmoduleattr("sys", NULL)
373373

374374
# TODO: test PyImport_GetImporter()
375375
# TODO: test PyImport_ReloadModule()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Add :c:func:`PyImport_GetModuleAttr` and :c:func:`PyImport_GetModuleAttrString`
1+
Add :c:func:`PyImport_ImportModuleAttr` and :c:func:`PyImport_ImportModuleAttrString`
22
helper functions to import a module and get an attribute of the module. Patch
33
by Victor Stinner.

Modules/_ctypes/callbacks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
492492
if (context == NULL)
493493
context = PyUnicode_InternFromString("_ctypes.DllGetClassObject");
494494

495-
func = PyImport_GetModuleAttrString("ctypes", "DllGetClassObject");
495+
func = PyImport_ImportModuleAttrString("ctypes", "DllGetClassObject");
496496
if (!func) {
497497
PyErr_WriteUnraisable(context ? context : Py_None);
498498
/* There has been a warning before about this already */

Modules/_ctypes/stgdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct
257257
goto error;
258258
}
259259

260-
PyObject *layout_func = PyImport_GetModuleAttrString("ctypes._layout",
260+
PyObject *layout_func = PyImport_ImportModuleAttrString("ctypes._layout",
261261
"get_layout");
262262
if (!layout_func) {
263263
goto error;

Modules/_cursesmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ _PyCursesCheckFunction(int called, const char *funcname)
226226
if (called == TRUE) {
227227
return 1;
228228
}
229-
PyObject *exc = PyImport_GetModuleAttrString("_curses", "error");
229+
PyObject *exc = PyImport_ImportModuleAttrString("_curses", "error");
230230
if (exc != NULL) {
231231
PyErr_Format(exc, "must call %s() first", funcname);
232232
Py_DECREF(exc);

Modules/_datetimemodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
18391839
assert(object && format && timetuple);
18401840
assert(PyUnicode_Check(format));
18411841

1842-
PyObject *strftime = PyImport_GetModuleAttrString("time", "strftime");
1842+
PyObject *strftime = PyImport_ImportModuleAttrString("time", "strftime");
18431843
if (strftime == NULL) {
18441844
return NULL;
18451845
}
@@ -2021,7 +2021,7 @@ static PyObject *
20212021
time_time(void)
20222022
{
20232023
PyObject *result = NULL;
2024-
PyObject *time = PyImport_GetModuleAttrString("time", "time");
2024+
PyObject *time = PyImport_ImportModuleAttrString("time", "time");
20252025

20262026
if (time != NULL) {
20272027
result = PyObject_CallNoArgs(time);
@@ -2039,7 +2039,7 @@ build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag)
20392039
PyObject *struct_time;
20402040
PyObject *result;
20412041

2042-
struct_time = PyImport_GetModuleAttrString("time", "struct_time");
2042+
struct_time = PyImport_ImportModuleAttrString("time", "struct_time");
20432043
if (struct_time == NULL) {
20442044
return NULL;
20452045
}

0 commit comments

Comments
 (0)