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

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

Closed
vstinner opened this issue Dec 28, 2008 · 5 comments
Closed

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

vstinner opened this issue Dec 28, 2008 · 5 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

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']

@vstinner
Copy link
Member Author

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.

@vstinner vstinner added the type-bug An unexpected behavior, bug, or error label Dec 28, 2008
@vstinner
Copy link
Member Author

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'

@vstinner
Copy link
Member Author

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.

@vstinner
Copy link
Member Author

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 ;-)

@vstinner
Copy link
Member Author

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant