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
SpooledTemporaryFile's name property is broken #54564
Comments
>>> import tempfile
>>> tempfile.SpooledTemporaryFile().name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/giampaolo/svn/python-2.7/Lib/tempfile.py", line 574, in name
return self._file.name
AttributeError: 'cStringIO.StringO' object has no attribute 'name' |
What makes you think SpooledTemporaryFile *has* a name attribute? :) Seriously, though, I presume this bug report is asking for either a better error message or for .name to raise an attribute error on a SpooledTemporaryFile? |
Yes, sorry, I should have been less concise. =)
I'm not sure what's better. I must be honest and say that I opened this report more to signal this behavior rather than provide a solution, though. |
From the doc of tempfile.NamedTemporaryFile: “This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file system (on Unix, the directory entry is not unlinked). That name can be retrieved from the name member of the file object. Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).” |
Éric: right, but we're talking about *Spooled*Temprorary file, which doesn't say anything about a name, and in fact says that the data is kept in memory (which implies it has no name). |
Wow, brain fail. What I actually wanted to say: SpooledTemporaryFile “operates exactly as TemporaryFile() does”, which is not guaranteed to have a name. The definition of file-like object (linked from tempfile docs) says nothing about a name either. Therefore, I think the presence of this attribute is a bug. Adding Collin to nosy, as the committer of SpooledTemporaryFile. |
Also "encoding" and "mode" properties fail in the same manner. |
Here is a patch which implements properties for which it has a sense and remove if there is no sense. |
New changeset 5c2ff6e64c47 by Serhiy Storchaka in branch '2.7': New changeset dfc6902b63d7 by Serhiy Storchaka in branch '3.2': New changeset f36d8ba4eeef by Serhiy Storchaka in branch '3.3': New changeset f1a13191f0c8 by Serhiy Storchaka in branch 'default': |
New changeset 6e9210a092cf by Serhiy Storchaka in branch '3.2': New changeset b5074ed74ec3 by Serhiy Storchaka in branch '3.3': New changeset 029011429f80 by Serhiy Storchaka in branch 'default': |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: