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 — io class name are hardcoded in reprs · Issue #66060 · python/cpython

io class name are hardcoded in reprs #66060

New issue
Copy link
New issue
Copy link
Closed
#30824
Closed
io class name are hardcoded in reprs#66060
#30824
Copy link
Labels
easyextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@serhiy-storchaka
serhiy-storchaka
opened on Jun 24, 2014
Issue body actions
BPO 21861
Nosy @rhettinger, @pitrou, @benjaminp, @PCManticore, @hynek, @serhiy-storchaka, @MojoVampire, @aisk, @Windsooon
PRs
  • bpo-21861: Improve _io.FileIO.__repr__ #14774
  • gh-66060: Use actual class name in some _io type's __repr__ #30824
  • 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 = None
    created_at = <Date 2014-06-24.17:36:58.710>
    labels = ['extension-modules', 'easy', 'type-bug', 'expert-IO']
    title = 'io class name are hardcoded in reprs'
    updated_at = <Date 2022-01-23.10:01:52.325>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2022-01-23.10:01:52.325>
    actor = 'asaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules', 'IO']
    creation = <Date 2014-06-24.17:36:58.710>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 21861
    keywords = ['patch', 'easy']
    message_count = 6.0
    messages = ['221476', '221990', '221993', '222011', '222939', '342684']
    nosy_count = 12.0
    nosy_names = ['rhettinger', 'pitrou', 'benjamin.peterson', 'stutzbach', 'Claudiu.Popa', 'hynek', 'piotr.dobrogost', 'serhiy.storchaka', 'josh.r', 'asaka', 'Windson Yang', 'Philip Dye']
    pr_nums = ['14774', '30824']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21861'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    Activity

    1. serhiy-storchaka commented on Jun 24, 2014

      @serhiy-storchaka
      serhiy-storchaka
      on Jun 24, 2014
      MemberAuthor
      More actions
      >>> import io
      >>> class F(io.FileIO): pass
      ... 
      >>> f = F('/dev/null', 'r')
      >>> f
      <_io.FileIO name='/dev/null' mode='rb'>
      >>> class B(io.BufferedReader): pass
      ... 
      >>> b = B(f)
      >>> b
      <B name='/dev/null'>
      >>> class T(io.TextIOBufferedReader): pass
      io.TextIOBase(     io.TextIOWrapper(  
      >>> class T(io.TextIOWrapper): pass
      ... 
      >>> t = T(b)
      >>> t
      <_io.TextIOWrapper name='/dev/null' encoding='UTF-8'>

      Expected results are "<main.F name='/dev/null' mode='rb'>", "<main.B name='/dev/null'>" and "<main.T name='/dev/null' encoding='UTF-8'>". Usually reprs of subclass instances substitute actual module and class names.

    2. serhiy-storchaka
      added
      extension-modulesC modules in the Modules dirC modules in the Modules dir
      topic-IO
      easy
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Jun 24, 2014
    3. PCManticore commented on Jun 30, 2014

      @PCManticore
      PCManticoremannequin
      on Jun 30, 2014
      Mannequin
      More actions

      The same should be done for _pyio?

    4. MojoVampire commented on Jun 30, 2014

      @MojoVampire
      MojoVampiremannequin
      on Jun 30, 2014
      Mannequin
      More actions

      Is it common for C implementations to introspect to figure out their "real" name? I do this manually for reprs of my user defined classes, but I haven't noticed many built-ins that consider extensibility for the repr. Maybe I'm just not using the classes that do it or I'm overriding the repr without checking?

      I just tested, and it looks like frozenset has a subclass friendly repr, while bytearray does not as of 3.4.0. Seems like it might make sense to first determine if introspection should be the default; it would mean a little code bloat every time it's done.

    5. rhettinger commented on Jul 1, 2014

      @rhettinger
      rhettinger
      on Jul 1, 2014
      Contributor
      More actions

      Usually reprs of subclass instances substitute actual module
      and class names.

      This is a sensible idea that makes life easier for people writing subclasses.

      +1 for your suggestion.

    6. serhiy-storchaka commented on Jul 13, 2014

      @serhiy-storchaka
      serhiy-storchaka
      on Jul 13, 2014
      MemberAuthor
      More actions

      I now see that this issue is not so easy from C side.

      And more, it is very uncommon for either Python or C implementations (especial C implementations) to introspect to figure out their "real" name. Existing cases are rather exceptions. And in many case this is only a side effect of sharing an implementation between several classes (set and frozenset, three buffered file classes in io, etc). In many cases repr's flexibility is limited: hardcoded or omitted module name, used class's __name__ instead of __qualname__, etc.

      This should be discussed on Python-Dev maillist.

    7. Windsooon commented on May 17, 2019

      @Windsooon
      Windsooonmannequin
      on May 17, 2019
      Mannequin
      More actions

      IIUC, in the c code we just hardcode the name "_io.FileIO" for "PyFileIO_Type" in https://github.com/python/cpython/blob/master/Modules/_io/fileio.c#L1180. If we want to get a dynamic name, we should replace the hardcode name with the module name (like "__main__"). I found this also happens on other modules like collections.

    8. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    9. erlend-aasland
      linked a pull request that will close this issuegh-66060: Use actual class name in some `_io` type's `__repr__` #30824on Jan 9, 2024
    10. erlend-aasland
      closed this as completedin #30824on Jan 9, 2024
    11. erlend-aasland
      added a commit that references this issue on Jan 9, 2024

      gh-66060: Use actual class name in _io type's __repr__ (#30824)

      623b338
    12. kulikjak
      added a commit that references this issue on Jan 22, 2024

      pythongh-66060: Use actual class name in _io type's __repr__ (python#…

      0327886
    13. aisk
      added a commit that references this issue on Feb 11, 2024

      pythongh-66060: Use actual class name in _io type's __repr__ (python#…

      18a6235
    14. Glyphack
      added a commit that references this issue on Sep 2, 2024

      pythongh-66060: Use actual class name in _io type's __repr__ (python#…

      0fed9e7
    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

      easyextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-IOtype-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.