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) * |
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) * |
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) * |
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) * |
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) * |
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) * |
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) * |
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) * |
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) * |
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) * |
Date: 2012-09-21 16:38 |
Patch looks fine, except please fix 80 columns.
|
msg170905 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
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) * |
Date: 2012-09-21 17:17 |
LGTM. Serhiy, you have the commit bit?
|
msg170908 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2012-09-21 17:53 |
> Serhiy, you have the commit bit?
It is zero.
|
msg170934 - (view) |
Author: Larry Hastings (larry) * |
Date: 2012-09-21 22:13 |
Georg: this okay to check in? It passes the regression test.
|
msg170954 - (view) |
Author: Georg Brandl (georg.brandl) * |
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) |
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) * |
Date: 2013-01-07 21:20 |
Fixed. Thank you for report, John.
|
|
Date |
User |
Action |
Args |
2022-04-11 14:57:36 | admin | set | github: 60176 |
2013-01-07 21:20:17 | serhiy.storchaka | set | status: open -> closed versions:
+ Python 3.4 messages:
+ msg179284
resolution: fixed stage: resolved |
2013-01-07 21:18:25 | python-dev | set | nosy:
+ python-dev messages:
+ msg179283
|
2013-01-07 16:29:56 | serhiy.storchaka | set | assignee: serhiy.storchaka |
2012-09-22 06:44:18 | georg.brandl | set | priority: release blocker -> normal
messages:
+ msg170954 |
2012-09-21 22:13:28 | larry | set | nosy:
+ georg.brandl messages:
+ msg170934
|
2012-09-21 17:53:55 | serhiy.storchaka | set | messages:
+ msg170908 |
2012-09-21 17:17:00 | larry | set | messages:
+ msg170906 |
2012-09-21 17:09:02 | serhiy.storchaka | set | files:
- posix_path_converter_2.patch |
2012-09-21 17:08:59 | serhiy.storchaka | set | files:
- posix_path_converter.patch |
2012-09-21 17:08:40 | serhiy.storchaka | set | files:
+ posix_path_converter_3.patch
messages:
+ msg170905 |
2012-09-21 16:38:45 | larry | set | messages:
+ msg170902 |
2012-09-21 14:08:12 | jftuga | set | messages:
+ msg170890 |
2012-09-21 08:50:54 | serhiy.storchaka | set | files:
+ posix_path_converter_2.patch
messages:
+ msg170867 |
2012-09-21 07:10:17 | larry | set | messages:
+ msg170865 |
2012-09-21 07:07:41 | serhiy.storchaka | set | messages:
+ msg170864 |
2012-09-20 21:43:34 | larry | set | messages:
+ msg170855 |
2012-09-20 17:54:58 | serhiy.storchaka | set | files:
+ posix_path_converter.patch keywords:
+ patch messages:
+ msg170825
|
2012-09-20 12:13:20 | vstinner | set | priority: normal -> release blocker
messages:
+ msg170806 |
2012-09-20 12:12:37 | vstinner | set | nosy:
+ larry, serhiy.storchaka messages:
+ msg170805
|
2012-09-20 12:08:17 | vstinner | set | nosy:
+ vstinner messages:
+ msg170804
|
2012-09-19 16:27:12 | christian.heimes | set | keywords:
+ 3.3regression nosy:
+ christian.heimes messages:
+ msg170727
|
2012-09-19 16:12:01 | jftuga | create | |