Skip to content

os.fspath() should not use repr() on error #71419

Closed

Description

@JelleZijlstra
BPO 27232
Nosy @ethanfurman, @berkerpeksag, @JelleZijlstra
Files
  • fspath-exception.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 = None
    closed_at = <Date 2016-10-06.11:09:54.441>
    created_at = <Date 2016-06-05.16:58:05.418>
    labels = ['type-bug', 'library']
    title = 'os.fspath() should not use repr() on error'
    updated_at = <Date 2016-10-06.11:09:54.439>
    user = 'https://github.com/JelleZijlstra'

    bugs.python.org fields:

    activity = <Date 2016-10-06.11:09:54.439>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-10-06.11:09:54.441>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2016-06-05.16:58:05.418>
    creator = 'JelleZijlstra'
    dependencies = []
    files = ['43240']
    hgrepos = []
    issue_num = 27232
    keywords = ['patch']
    message_count = 4.0
    messages = ['267432', '267519', '267529', '278184']
    nosy_count = 4.0
    nosy_names = ['SilentGhost', 'ethan.furman', 'berker.peksag', 'JelleZijlstra']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27232'
    versions = ['Python 3.6']

    Activity

    1. JelleZijlstra commented on Jun 5, 2016

      @JelleZijlstra
      MemberAuthor

      The current implementation of os.fspath() outputs something like this if you call os.fspath(0):

      expected str, bytes or os.PathLike object, not <class 'int' at 0x10a3f3e50>

      This patch changes the output to:

      expected str, bytes or os.PathLike object, not int

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jun 5, 2016
    3. SilentGhost commented on Jun 6, 2016

      SilentGhostmannequin
      Mannequin

      This is behaviour introduced by bpo-25548, it would make sense to me to discuss this problem there if you think it's necessary. repr in error messages has been a standard approach in Python for a very long time, however.

    4. JelleZijlstra commented on Jun 6, 2016

      @JelleZijlstra
      MemberAuthor

      No, that issue just adds the address to the repr() of types. It is not normal to use repr for type objects in error messages:

      >>> int(None)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
      >>> open(None, 0)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: open() argument 2 must be str, not int
      >>> os.fspath(None)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: expected str, bytes or os.PathLike object, not <class 'NoneType' at 0x1086bb638>
    5. berkerpeksag commented on Oct 6, 2016

      @berkerpeksag
      Member

      This has already been fixed in ea7b6a7827a4:

          >>> import os
          >>> os.fspath(None)
          Traceback (most recent call last):
            File "<stdin>", line 1, in <module>
          TypeError: expected str, bytes or os.PathLike object, not NoneType
    6. 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

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions