Skip to content

PyFile_FromFd() doesn't set the file name #49012

Closed

Description

@vstinner
BPO 4762
Nosy @pitrou, @vstinner

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 2009-03-25.00:06:58.567>
created_at = <Date 2008-12-28.16:57:09.393>
labels = ['type-bug']
title = "PyFile_FromFd() doesn't set the file name"
updated_at = <Date 2010-08-13.13:36:35.408>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2010-08-13.13:36:35.408>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2009-03-25.00:06:58.567>
closer = 'vstinner'
components = ['None']
creation = <Date 2008-12-28.16:57:09.393>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 4762
keywords = []
message_count = 5.0
messages = ['78419', '78421', '78422', '84132', '113772']
nosy_count = 2.0
nosy_names = ['pitrou', 'vstinner']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue4762'
versions = ['Python 3.1']

Activity

  1. vstinner commented on Dec 28, 2008

    @vstinner
    MemberAuthor

    PyFile_FromFd() never changes the name of new created file object:

    $ ./python -c "import sys; print(sys.stdout.buffer.name, 
    sys.stdout.name)"
    0 0

    Expected result: <stdout> <stdout>.

    ---

    Binary mode:

    • with buffering == 0, the file object is a FileIO. Changing the name
      can be done with: file._name=new_name
    • with buffering != 0, the file object is a BufferedXXX() and
      file.raw is a FileIO. So we have to set: file.raw._name=new_name

    If text mode, the file object is a TextIOWrapper and file.raw is a
    BufferedXXX() (buffering=0 is forbidden for text file). So changing
    the name can be done with: file.raw.raw._name=newname.

    I'm not sure of the classes/types.

    Note: PyFile_FromFd() shouldn't use PyErr_Clear() if changing the name
    fails.

  2. vstinner commented on Dec 28, 2008

    @vstinner
    MemberAuthor

    In my last patch to fix the issue bpo-4705, I replaced PyFile_FromFd() by
    custom code which set correctly the file name.

    PyFile_FromFd() is also used in:

    • _Py_DisplaySourceLine(): name is not used, only
      PyFile_GetLine(file)
    • call_find_module() (imp.find_module()): return the file object with
      the wrong name

    Example with imp:

    >>> file, filename, extra = imp.find_module("os")
    >>> file
    <io.TextIOWrapper object at 0xb7b6ea6c>
    >>> file.name
    4
    >>> filename
    '/home/SHARE/SVN/py3k/Lib/os.py'
  3. vstinner commented on Dec 28, 2008

    @vstinner
    MemberAuthor

    In my last patch to fix the issue bpo-4705, I replaced PyFile_FromFd()
    by custom code which set correctly the file name.

    The standard I/O: sys.stdin, sys.stdout and sys.stderr.

  4. vstinner commented on Mar 25, 2009

    @vstinner
    MemberAuthor

    In py3k, standard streams' names are now correct (since the io-c
    merge):

    Python 3.1a1+ (py3k:70589M, Mar 25 2009, 01:01:13)
    >>> import sys
    >>> sys.stdin.name, sys.stdout.name, sys.stderr.name
    ('<stdin>', '<stdout>', '<stderr>')

    The last problem occurs with imp.find_module(). But imp.find_module()
    also returns a "filename" argument, so I don't think that the issue
    really matters. Let's close it ;-)

  5. vstinner commented on Aug 13, 2010

    @vstinner
    MemberAuthor

    r83973 ignores the name argument of PyFile_FromFd() because it was already ignored (it did always produce an error).

  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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions