New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os.fspath() should not use repr() on error #71419
Comments
The current implementation of os.fspath() outputs something like this if you call os.fspath(0): expected str, bytes or os.PathLike object, not <class 'int' at 0x10a3f3e50> This patch changes the output to: expected str, bytes or os.PathLike object, not int |
This is behaviour introduced by bpo-25548, it would make sense to me to discuss this problem there if you think it's necessary. repr in error messages has been a standard approach in Python for a very long time, however. |
No, that issue just adds the address to the repr() of types. It is not normal to use repr for type objects in error messages: >>> int(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
>>> open(None, 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: open() argument 2 must be str, not int
>>> os.fspath(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected str, bytes or os.PathLike object, not <class 'NoneType' at 0x1086bb638> |
This has already been fixed in ea7b6a7827a4: >>> import os
>>> os.fspath(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected str, bytes or os.PathLike object, not NoneType |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: