New error messages in Python 3.13
Updated
Python 3.13 made tracebacks colourful and taught the interpreter to recognise one of the most confusing mistakes: a script named like the module it imports. Each example below ran on 3.12 and on 3.13.
Colour in tracebacks
In a terminal, tracebacks are now in colour by default. The PYTHON_COLORS environment variable switches it, and the cross-tool NO_COLOR and FORCE_COLOR variables are honoured. Output sent to a file or a pipe stays plain, which is why the runs on this page have no colour.
A script named like a standard library module
import random
print(random.randint(1, 6))Traceback (most recent call last):
File "/home/me/project/random.py", line 1, in <module>
import random
File "/home/me/project/random.py", line 3, in <module>
print(random.randint(1, 6))
^^^^^^^^^^^^^^
AttributeError: module 'random' has no attribute 'randint' (consider renaming '/home/me/project/random.py' since it has the same name as the standard library module named 'random' and prevents importing that standard library module)| Python | Prints |
|---|---|
| 3.12 | AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import) |
| 3.13 | AttributeError: module 'random' has no attribute 'randint' (consider renaming '/home/me/project/random.py' since it has the same name as the standard library module named 'random' and prevents importing that standard library module) |
Run on CPython 3.12.15 and 3.13.17, on October 25, 2026.
A script named like a library you meant to import
import numpy as np
print(np.array([1, 2, 3]))Traceback (most recent call last):
File "/home/me/project/numpy.py", line 1, in <module>
import numpy as np
File "/home/me/project/numpy.py", line 3, in <module>
print(np.array([1, 2, 3]))
^^^^^^^^
AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/me/project/numpy.py' if it has the same name as a library you intended to import)| Python | Prints |
|---|---|
| 3.12 | AttributeError: partially initialized module 'numpy' has no attribute 'array' (most likely due to a circular import) |
| 3.13 | AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/me/project/numpy.py' if it has the same name as a library you intended to import) |
Run on CPython 3.12.15 and 3.13.17, on October 25, 2026.
Suggestions for keyword arguments
A misspelt keyword argument gets the closest real parameter name.
print("Better error messages!".split(max_split=1))Traceback (most recent call last):
File "/home/me/project/main.py", line 1, in <module>
print("Better error messages!".split(max_split=1))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'?| Python | Prints |
|---|---|
| 3.12 | TypeError: 'max_split' is an invalid keyword argument for split() |
| 3.13 | TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'? |
Run on CPython 3.12.15 and 3.13.17, on October 25, 2026.
Sources
- What's New in Python 3.13: improved error messages, Python documentation
Read on October 25, 2026.