GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — wrong error message for os.path.getsize · Issue #60176 · python/cpython

wrong error message for os.path.getsize #60176

New issue
Copy link
New issue
Copy link
Closed
Closed
wrong error message for os.path.getsize#60176
Copy link
Assignees
serhiy-storchaka
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

jftuga
mannequin
opened on Sep 19, 2012
Issue body actions
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']

    Activity

    1. jftuga commented on Sep 19, 2012

      @jftuga
      jftugamannequin
      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.

    2. jftuga
      added
      extension-modulesC modules in the Modules dirC modules in the Modules dir
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Sep 19, 2012
    3. tiran commented on Sep 19, 2012

      @tiran
      tiran
      on Sep 19, 2012
      Member
      More actions

      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]
    4. vstinner commented on Sep 20, 2012

      @vstinner
      vstinner
      on Sep 20, 2012
      Member
      More actions

      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
    5. vstinner commented on Sep 20, 2012

      @vstinner
      vstinner
      on Sep 20, 2012
      Member
      More actions

      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.

    6. vstinner commented on Sep 20, 2012

      @vstinner
      vstinner
      on Sep 20, 2012
      Member
      More actions

      Set the priority to release blocker until it is decided if this issue is a regression, or a new feature :-)

    7. vstinner
      added
      release-blocker
      on Sep 20, 2012
    8. serhiy-storchaka commented on Sep 20, 2012

      @serhiy-storchaka
      serhiy-storchaka
      on Sep 20, 2012
      Member
      More actions

      Here is a patch.

      Are there any tests for string and bytes arguments as filenames? I will add
      float and list there.

    9. larryhastings commented on Sep 20, 2012

      @larryhastings
      larryhastings
      on Sep 20, 2012
      Contributor
      More actions

      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.

    10. serhiy-storchaka commented on Sep 21, 2012

      @serhiy-storchaka
      serhiy-storchaka
      on Sep 21, 2012
      Member
      More actions

      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"

    11. larryhastings commented on Sep 21, 2012

      @larryhastings
      larryhastings
      on Sep 21, 2012
      Contributor
      More actions

      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.

    12. serhiy-storchaka commented on Sep 21, 2012

      @serhiy-storchaka
      serhiy-storchaka
      on Sep 21, 2012
      Member
      More actions

      Patch updated. Added tests.

    13. jftuga commented on Sep 21, 2012

      @jftuga
      jftugamannequin
      on Sep 21, 2012
      MannequinAuthor
      More actions

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

    14. larryhastings commented on Sep 21, 2012

      @larryhastings
      larryhastings
      on Sep 21, 2012
      Contributor
      More actions

      Patch looks fine, except please fix 80 columns.

    15. serhiy-storchaka commented on Sep 21, 2012

      @serhiy-storchaka
      serhiy-storchaka
      on Sep 21, 2012
      Member
      More actions

      Patch looks fine, except please fix 80 columns.

      Patch updated. Long lines in tests fixed.

    16. larryhastings commented on Sep 21, 2012

      @larryhastings
      larryhastings
      on Sep 21, 2012
      Contributor
      More actions

      LGTM. Serhiy, you have the commit bit?

    17. serhiy-storchaka commented on Sep 21, 2012

      @serhiy-storchaka
      serhiy-storchaka
      on Sep 21, 2012
      Member
      More actions

      Serhiy, you have the commit bit?

      It is zero.

    18. larryhastings commented on Sep 21, 2012

      @larryhastings
      larryhastings
      on Sep 21, 2012
      Contributor
      More actions

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

    19. birkenfeld commented on Sep 22, 2012

      @birkenfeld
      birkenfeld
      on Sep 22, 2012
      Member
      More actions

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

    20. birkenfeld
      removed
      release-blocker
      on Sep 22, 2012
    21. serhiy-storchaka
      self-assigned this
      on Jan 7, 2013
    22. python-dev commented on Jan 7, 2013

      @python-dev
      python-devmannequin
      on Jan 7, 2013
      Mannequin
      More actions

      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

    23. serhiy-storchaka commented on Jan 7, 2013

      @serhiy-storchaka
      serhiy-storchaka
      on Jan 7, 2013
      Member
      More actions

      Fixed. Thank you for report, John.

    24. serhiy-storchaka
      closed this as completedon Jan 7, 2013
    25. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @serhiy-storchaka
      serhiy-storchaka

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.