Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 500f533

Browse filesBrowse files
authored
gh-123930: Better error for "from imports" when script shadows module (#123929)
1 parent 3f24bde commit 500f533
Copy full SHA for 500f533

File tree

6 files changed

+342
-171
lines changed
Filter options

6 files changed

+342
-171
lines changed

‎Doc/whatsnew/3.13.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.13.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Improved error messages
274274
File "/home/me/random.py", line 3, in <module>
275275
print(random.randint(5))
276276
^^^^^^^^^^^^^^
277-
AttributeError: module 'random' has no attribute 'randint' (consider renaming '/home/me/random.py' since it has the same name as the standard library module named 'random' and the import system gives it precedence)
277+
AttributeError: module 'random' has no attribute 'randint' (consider renaming '/home/me/random.py' since it has the same name as the standard library module named 'random' and prevents importing that standard library module)
278278
279279
Similarly, if a script has the same name as a third-party
280280
module that it attempts to import and this results in errors,
@@ -289,7 +289,7 @@ Improved error messages
289289
File "/home/me/numpy.py", line 3, in <module>
290290
np.array([1, 2, 3])
291291
^^^^^^^^
292-
AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/me/numpy.py' if it has the same name as a third-party module you intended to import)
292+
AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/me/numpy.py' if it has the same name as a library you intended to import)
293293
294294
(Contributed by Shantanu Jain in :gh:`95754`.)
295295

‎Include/internal/pycore_moduleobject.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_moduleobject.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ extern "C" {
1111
extern void _PyModule_Clear(PyObject *);
1212
extern void _PyModule_ClearDict(PyObject *);
1313
extern int _PyModuleSpec_IsInitializing(PyObject *);
14+
extern int _PyModuleSpec_GetFileOrigin(PyObject *, PyObject **);
15+
extern int _PyModule_IsPossiblyShadowing(PyObject *);
1416

1517
extern int _PyModule_IsExtension(PyObject *obj);
1618

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.