Skip to content
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

Closed
jftuga mannequin opened this issue Sep 19, 2012 · 19 comments
Closed

wrong error message for os.path.getsize #60176

jftuga mannequin opened this issue Sep 19, 2012 · 19 comments
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@jftuga
Copy link
Mannequin

jftuga mannequin commented Sep 19, 2012

BPO 15972
Nosy @birkenfeld, @vstinner, @larryhastings, @tiran, @serhiy-storchaka, @jftuga
Files
  • posix_path_converter_3.patch
  • 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']

    @jftuga
    Copy link
    Mannequin Author

    jftuga mannequin commented Sep 19, 2012

    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.

    @jftuga jftuga mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Sep 19, 2012
    @tiran
    Copy link
    Member

    tiran commented 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
    Copy link
    Member

    vstinner commented 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 integer

    @vstinner
    Copy link
    Member

    vstinner commented 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 <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 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
    Copy link
    Member

    vstinner commented 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
    Copy link
    Member

    serhiy-storchaka commented 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
    Copy link
    Contributor

    larryhastings commented 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").

                                                            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.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented 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
    Copy link
    Contributor

    larryhastings commented 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
    Copy link
    Member

    serhiy-storchaka commented Sep 21, 2012

    Patch updated. Added tests.

    @jftuga
    Copy link
    Mannequin Author

    jftuga mannequin commented Sep 21, 2012

    OP here. These error messages are much better. Thanks!

    @larryhastings
    Copy link
    Contributor

    larryhastings commented Sep 21, 2012

    Patch looks fine, except please fix 80 columns.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Sep 21, 2012

    Patch looks fine, except please fix 80 columns.

    Patch updated. Long lines in tests fixed.

    @larryhastings
    Copy link
    Contributor

    larryhastings commented Sep 21, 2012

    LGTM. Serhiy, you have the commit bit?

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Sep 21, 2012

    Serhiy, you have the commit bit?

    It is zero.

    @larryhastings
    Copy link
    Contributor

    larryhastings commented Sep 21, 2012

    Georg: this okay to check in? It passes the regression test.

    @birkenfeld
    Copy link
    Member

    birkenfeld commented Sep 22, 2012

    This certainly isn't a release blocker. Check it into default, and it will go into 3.3.1.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 7, 2013

    New changeset 1b68dc917321 by Serhiy Storchaka in branch '3.3':
    Issue bpo-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 bpo-15972: Fix error messages when os functions expecting a file name or
    http://hg.python.org/cpython/rev/71fb426ee972

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Jan 7, 2013

    Fixed. Thank you for report, John.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants