GeezerVison is showing github.com — wrong error message for os.path.getsize · Issue #60176 · python/cpython
wrong error message for os.path.getsize #60176Description
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:
assignee = 'https://github.com/serhiy-storchaka'
closed_at = <Date 2013-01-07.21:20:17.524>
created_at = <Date 2012-09-19.16:12:01.804>
labels = ['extension-modules', 'type-bug']
title = 'wrong error message for os.path.getsize'
updated_at = <Date 2013-01-07.21:20:17.521>
user = 'https://github.com/jftuga'
bugs.python.org fields:
activity = <Date 2013-01-07.21:20:17.521>
actor = 'serhiy.storchaka'
assignee = 'serhiy.storchaka'
closed = True
closed_date = <Date 2013-01-07.21:20:17.524>
closer = 'serhiy.storchaka'
components = ['Extension Modules']
creation = <Date 2012-09-19.16:12:01.804>
creator = 'jftuga'
dependencies = []
files = ['27247']
hgrepos = []
issue_num = 15972
keywords = ['patch', '3.3regression']
message_count = 19.0
messages = ['170726', '170727', '170804', '170805', '170806', '170825', '170855', '170864', '170865', '170867', '170890', '170902', '170905', '170906', '170908', '170934', '170954', '179283', '179284']
nosy_count = 7.0
nosy_names = ['georg.brandl', 'vstinner', 'larry', 'christian.heimes', 'python-dev', 'serhiy.storchaka', 'jftuga']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue15972'
versions = ['Python 3.3', 'Python 3.4']
Activityjftuga commented on Sep 19, 2012 MannequinAuthor More actions import os.path
a = [ r'c:\Windows\notepad.exe' ]
print( os.path.getsize(a) )
Under Python 3.2.3, this error message is returned:
File "c:\python32\lib\genericpath.py", line 49, in getsize
return os.stat(filename).st_size
TypeError: Can't convert 'list' object to str implicitly
Under Python 3.3.0rc2, this error message is returned:
File "c:\Python33\lib\genericpath.py", line 49, in getsize
return os.stat(filename).st_size
TypeError: an integer is required
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. tiran commented on Sep 19, 2012 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] vstinner commented on Sep 20, 2012 It looks like os.stat() and os.path.getsize() converts the list into a byte string. It does something like:
>> x=[]; y=bytes(x); print(y.decode("ascii"))
>>> 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 integervstinner commented on Sep 20, 2012 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
user: Larry Hastings <[email protected]>
date: Fri Jun 22 16:30:09 2012 -0700
files: Doc/library/os.rst Lib/os.py Lib/shutil.py Lib/test/support.py Lib/test/test_os.py Lib/test/test_posix.py Lib/test/test_shutil.py Misc/NEWS Modules/posixmodule.c
description:
Issue bpo-14626: Large refactoring of functions / parameters in the os module.
Many functions now support "dir_fd" and "follow_symlinks" parameters;
some also support accepting an open file descriptor in place of of a path
string. Added os.support_* collections as LBYL helpers. Removed many
functions only previously seen in 3.3 alpha releases (often starting with
"f" or "l", or ending with "at"). Originally suggested by Serhiy Storchaka;
implemented by Larry Hastings. vstinner commented on Sep 20, 2012 Set the priority to release blocker until it is decided if this issue is a regression, or a new feature :-) serhiy-storchaka commented on Sep 20, 2012 Here is a patch.
Are there any tests for string and bytes arguments as filenames? I will add
float and list there. larryhastings commented on Sep 20, 2012 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. serhiy-storchaka commented on Sep 21, 2012
But please add regression tests checking
that the error message is what we want.
Immediately as soon as I find a suitable place for this test. Should be
somewhere tests for bytes/unicode filenames.
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.
"Invalid whence (%i, should be 0, 1 or 2)"
"expect bytes or str of length 1, or int, "
"argument should be bytes, buffer or ASCII string, "
"coercing to str: need bytes, bytearray or buffer-like object, %.80s found"
"character mapping must return integer, bytes or None, not %.400s" larryhastings commented on Sep 21, 2012 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. serhiy-storchaka commented on Sep 21, 2012 Patch updated. Added tests. jftuga commented on Sep 21, 2012 MannequinAuthor More actions OP here. These error messages are much better. Thanks! larryhastings commented on Sep 21, 2012 Patch looks fine, except please fix 80 columns. serhiy-storchaka commented on Sep 21, 2012
Patch looks fine, except please fix 80 columns.
Patch updated. Long lines in tests fixed. larryhastings commented on Sep 21, 2012 LGTM. Serhiy, you have the commit bit? serhiy-storchaka commented on Sep 21, 2012
Serhiy, you have the commit bit?
It is zero. larryhastings commented on Sep 21, 2012 Georg: this okay to check in? It passes the regression test. birkenfeld commented on Sep 22, 2012 This certainly isn't a release blocker. Check it into default, and it will go into 3.3.1. python-dev commented on Jan 7, 2013 serhiy-storchaka commented on Jan 7, 2013 Fixed. Thank you for report, John.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|