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
wrong error message for os.path.getsize #60176
Comments
import os.path
a = [ r'c:\Windows\notepad.exe' ]
print( os.path.getsize(a) )Under Python 3.2.3, this error message is returned: Under Python 3.3.0rc2, this error message is returned: I feel like the 3.2.3 behavior is more accurate and would like to propose that the 3.3 error message says something about a list instead of an integer. |
|
Linux: >>> os.stat([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: ''
[60996 refs]
>>> os.stat([None])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: an integer is required
[60993 refs] |
|
It looks like os.stat() and os.path.getsize() converts the list into a byte string. It does something like:
>>> x=[65, 66, 67]; y=bytes(x); print(y.decode("ascii"))
ABC
>>> x=[None]; y=bytes(x); print(y.decode("ascii"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer |
|
Functions of the os module uses PyUnicode_FSConverter() function (which uses PyBytes_Check() on bytes) in Python 3.2, whereas PyBytes_FromObject() is used in Python 3.3. Related change: changeset: 77597:27f9c26fdd8b |
|
Set the priority to release blocker until it is decided if this issue is a regression, or a new feature :-) |
|
Here is a patch. Are there any tests for string and bytes arguments as filenames? I will add |
|
Patch looks like it'll work fine. But please add regression tests checking that the error message is what we want. Are the new error messages okay with the OP? It looks like now it'll throw TypeError("argument must be string, bytes or integer, not list"). I'd personally prefer the Oxford Comma there ("string, bytes, or integer"). But I don't know if there is a style preference one way or the other in Python error messages. |
Immediately as soon as I find a suitable place for this test. Should be
"Invalid whence (%i, should be 0, 1 or 2)" |
|
Ah! It seems Python is anti-Oxford Comma. Carry on! ;-) Wouldn't test_os be the natural place? I don't understand why you're having difficulty finding a suitable place. |
|
Patch updated. Added tests. |
|
OP here. These error messages are much better. Thanks! |
|
Patch looks fine, except please fix 80 columns. |
Patch updated. Long lines in tests fixed. |
|
LGTM. Serhiy, you have the commit bit? |
It is zero. |
|
Georg: this okay to check in? It passes the regression test. |
|
This certainly isn't a release blocker. Check it into default, and it will go into 3.3.1. |
|
New changeset 1b68dc917321 by Serhiy Storchaka in branch '3.3': New changeset 71fb426ee972 by Serhiy Storchaka in branch 'default': |
|
Fixed. Thank you for report, John. |
jftuga mannequin commentedSep 19, 2012
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: