homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: wrong error message for os.path.getsize
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: christian.heimes, georg.brandl, jftuga, larry, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: 3.3regression, patch

Created on 2012年09月19日 16:12 by jftuga, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
posix_path_converter_3.patch serhiy.storchaka, 2012年09月21日 17:08 review
Messages (19)
msg170726 - (view) Author: John Taylor (jftuga) * Date: 2012年09月19日 16:12
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.
msg170727 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012年09月19日 16:27
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]
msg170804 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012年09月20日 12:08
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 integer
msg170805 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012年09月20日 12:12
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 <larry@hastings.org>
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 #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.
msg170806 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012年09月20日 12:13
Set the priority to release blocker until it is decided if this issue is a regression, or a new feature :-)
msg170825 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012年09月20日 17:54
Here is a patch.
Are there any tests for string and bytes arguments as filenames? I will add 
float and list there.
msg170855 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012年09月20日 21:43
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").
 v
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.
msg170864 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012年09月21日 07:07
> 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"
msg170865 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012年09月21日 07:10
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.
msg170867 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012年09月21日 08:50
Patch updated. Added tests.
msg170890 - (view) Author: John Taylor (jftuga) * Date: 2012年09月21日 14:08
OP here. These error messages are much better. Thanks!
msg170902 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012年09月21日 16:38
Patch looks fine, except please fix 80 columns.
msg170905 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012年09月21日 17:08
> Patch looks fine, except please fix 80 columns.
Patch updated. Long lines in tests fixed.
msg170906 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012年09月21日 17:17
LGTM. Serhiy, you have the commit bit?
msg170908 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012年09月21日 17:53
> Serhiy, you have the commit bit?
It is zero.
msg170934 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012年09月21日 22:13
Georg: this okay to check in? It passes the regression test.
msg170954 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012年09月22日 06:44
This certainly isn't a release blocker. Check it into default, and it will go into 3.3.1.
msg179283 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013年01月07日 21:18
New changeset 1b68dc917321 by Serhiy Storchaka in branch '3.3':
Issue #15972: Fix error messages when os functions expecting a file name or
http://hg.python.org/cpython/rev/1b68dc917321
New changeset 71fb426ee972 by Serhiy Storchaka in branch 'default':
Issue #15972: Fix error messages when os functions expecting a file name or
http://hg.python.org/cpython/rev/71fb426ee972 
msg179284 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013年01月07日 21:20
Fixed. Thank you for report, John.
History
Date User Action Args
2022年04月11日 14:57:36adminsetgithub: 60176
2013年01月07日 21:20:17serhiy.storchakasetstatus: open -> closed
versions: + Python 3.4
messages: + msg179284

resolution: fixed
stage: resolved
2013年01月07日 21:18:25python-devsetnosy: + python-dev
messages: + msg179283
2013年01月07日 16:29:56serhiy.storchakasetassignee: serhiy.storchaka
2012年09月22日 06:44:18georg.brandlsetpriority: release blocker -> normal

messages: + msg170954
2012年09月21日 22:13:28larrysetnosy: + georg.brandl
messages: + msg170934
2012年09月21日 17:53:55serhiy.storchakasetmessages: + msg170908
2012年09月21日 17:17:00larrysetmessages: + msg170906
2012年09月21日 17:09:02serhiy.storchakasetfiles: - posix_path_converter_2.patch
2012年09月21日 17:08:59serhiy.storchakasetfiles: - posix_path_converter.patch
2012年09月21日 17:08:40serhiy.storchakasetfiles: + posix_path_converter_3.patch

messages: + msg170905
2012年09月21日 16:38:45larrysetmessages: + msg170902
2012年09月21日 14:08:12jftugasetmessages: + msg170890
2012年09月21日 08:50:54serhiy.storchakasetfiles: + posix_path_converter_2.patch

messages: + msg170867
2012年09月21日 07:10:17larrysetmessages: + msg170865
2012年09月21日 07:07:41serhiy.storchakasetmessages: + msg170864
2012年09月20日 21:43:34larrysetmessages: + msg170855
2012年09月20日 17:54:58serhiy.storchakasetfiles: + posix_path_converter.patch
keywords: + patch
messages: + msg170825
2012年09月20日 12:13:20vstinnersetpriority: normal -> release blocker

messages: + msg170806
2012年09月20日 12:12:37vstinnersetnosy: + larry, serhiy.storchaka
messages: + msg170805
2012年09月20日 12:08:17vstinnersetnosy: + vstinner
messages: + msg170804
2012年09月19日 16:27:12christian.heimessetkeywords: + 3.3regression
nosy: + christian.heimes
messages: + msg170727

2012年09月19日 16:12:01jftugacreate

AltStyle によって変換されたページ (->オリジナル) /