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
Copy file name to clipboardExpand all lines: Doc/whatsnew/3.13.rst
+34
Original file line number
Diff line number
Diff line change
@@ -104,6 +104,40 @@ Improved Error Messages
104
104
variables. See also :ref:`using-on-controlling-color`.
105
105
(Contributed by Pablo Galindo Salgado in :gh:`112730`.)
106
106
107
+
* A common mistake is to write a script with the same name as a
108
+
standard library module. When this results in errors, we now
109
+
display a more helpful error message:
110
+
111
+
.. code-block:: shell-session
112
+
113
+
$ python random.py
114
+
Traceback (most recent call last):
115
+
File "/home/random.py", line 1, in <module>
116
+
import random; print(random.randint(5))
117
+
^^^^^^^^^^^^^
118
+
File "/home/random.py", line 1, in <module>
119
+
import random; print(random.randint(5))
120
+
^^^^^^^^^^^^^^
121
+
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)
122
+
123
+
Similarly, if a script has the same name as a third-party
124
+
module it attempts to import, and this results in errors,
125
+
we also display a more helpful error message:
126
+
127
+
.. code-block:: shell-session
128
+
129
+
$ python numpy.py
130
+
Traceback (most recent call last):
131
+
File "/home/numpy.py", line 1, in <module>
132
+
import numpy as np; np.array([1,2,3])
133
+
^^^^^^^^^^^^^^^^^^
134
+
File "/home/numpy.py", line 1, in <module>
135
+
import numpy as np; np.array([1,2,3])
136
+
^^^^^^^^
137
+
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)
138
+
139
+
(Contributed by Shantanu Jain in :gh:`95754`.)
140
+
107
141
* When an incorrect keyword argument is passed to a function, the error message
108
142
now potentially suggests the correct keyword argument.
109
143
(Contributed by Pablo Galindo Salgado and Shantanu Jain in :gh:`107944`.)
0 commit comments