diff options
author | Shantanu <12621235+hauntsaninja@users.noreply.github.com> | 2024-04-23 01:24:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-23 01:24:21 (GMT) |
commit | 8e86579caef59fad0c54ac698d589f23a7951c55 (patch) | |
tree | e844412f935160dbe8b0b487b4f4fc03eaec1581 /Doc | |
parent | c9829eec0883a8991ea4d319d965e123a3cf6c20 (diff) | |
download | cpython-8e86579caef59fad0c54ac698d589f23a7951c55.zip cpython-8e86579caef59fad0c54ac698d589f23a7951c55.tar.gz cpython-8e86579caef59fad0c54ac698d589f23a7951c55.tar.bz2 |
gh-95754: Better error when script shadows a standard library or third party module (#113769)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/whatsnew/3.13.rst | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 67d1956..89694af 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -104,6 +104,40 @@ Improved Error Messages variables. See also :ref:`using-on-controlling-color`. (Contributed by Pablo Galindo Salgado in :gh:`112730`.) +* A common mistake is to write a script with the same name as a + standard library module. When this results in errors, we now + display a more helpful error message: + + .. code-block:: shell-session + + $ python random.py + Traceback (most recent call last): + File "/home/random.py", line 1, in <module> + import random; print(random.randint(5)) + ^^^^^^^^^^^^^ + File "/home/random.py", line 1, in <module> + import random; print(random.randint(5)) + ^^^^^^^^^^^^^^ + AttributeError: module 'random' has no attribute 'randint' (consider renaming '/home/random.py' since it has the same name as the standard library module named 'random' and the import system gives it precedence) + + Similarly, if a script has the same name as a third-party + module it attempts to import, and this results in errors, + we also display a more helpful error message: + + .. code-block:: shell-session + + $ python numpy.py + Traceback (most recent call last): + File "/home/numpy.py", line 1, in <module> + import numpy as np; np.array([1,2,3]) + ^^^^^^^^^^^^^^^^^^ + File "/home/numpy.py", line 1, in <module> + import numpy as np; np.array([1,2,3]) + ^^^^^^^^ + AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/numpy.py' if it has the same name as a third-party module you intended to import) + + (Contributed by Shantanu Jain in :gh:`95754`.) + * When an incorrect keyword argument is passed to a function, the error message now potentially suggests the correct keyword argument. (Contributed by Pablo Galindo Salgado and Shantanu Jain in :gh:`107944`.) |