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

tempfile.template is broken #54563

Closed
giampaolo opened this issue Nov 8, 2010 · 14 comments
Closed

tempfile.template is broken #54563

giampaolo opened this issue Nov 8, 2010 · 14 comments
Labels
stdlib Python modules in the Lib dir

Comments

@giampaolo
Copy link
Contributor

BPO 10354
Nosy @birkenfeld, @rhettinger, @gpshead, @ericvsmith, @giampaolo, @merwok, @bitdancer
Files
  • tempfile.patch
  • tempfile.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 2011-06-23.01:03:55.177>
    created_at = <Date 2010-11-08.11:28:09.694>
    labels = ['library']
    title = 'tempfile.template is broken'
    updated_at = <Date 2015-05-19.01:29:47.334>
    user = 'https://github.com/giampaolo'

    bugs.python.org fields:

    activity = <Date 2015-05-19.01:29:47.334>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-06-23.01:03:55.177>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2010-11-08.11:28:09.694>
    creator = 'giampaolo.rodola'
    dependencies = []
    files = ['19541', '19542']
    hgrepos = []
    issue_num = 10354
    keywords = ['patch']
    message_count = 14.0
    messages = ['120729', '120730', '120732', '120734', '120735', '120737', '120746', '120828', '120834', '120835', '138844', '138845', '243551', '243553']
    nosy_count = 8.0
    nosy_names = ['georg.brandl', 'rhettinger', 'gregory.p.smith', 'eric.smith', 'giampaolo.rodola', 'eric.araujo', 'r.david.murray', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue10354'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @giampaolo
    Copy link
    Contributor Author

    >>> import tempfile
    >>> tempfile.template = 'XXX'
    >>> tempfile.mkdtemp()
    '/tmp/tmpPf5lML'
    >>>

    Functions that use template use it as an argument default, so changing it afterwards has no effect.

    @giampaolo giampaolo added the stdlib Python modules in the Lib dir label Nov 8, 2010
    @giampaolo
    Copy link
    Contributor Author

    Patch in attachment.

    @ericvsmith
    Copy link
    Member

    The patch looks good to me, but it needs a test.

    @giampaolo
    Copy link
    Contributor Author

    Patch including tests is in attachment.
    I think I've just found two further bugs though:

    >>> tempfile.TemporaryFile().name
    '<fdopen>'
    >>> tempfile.TemporaryFile(prefix='xxx').name
    '<fdopen>'
    >>> 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'

    I'm going to open two separate tickets.

    @giampaolo
    Copy link
    Contributor Author

    Adding georg.brandl to nosy list as per misc/maintainers.rst.

    @giampaolo
    Copy link
    Contributor Author

    Created bpo-10355 for SpooledTemporaryFile bug while TemporaryFile having no name seems to be rightful.

    @bitdancer
    Copy link
    Member

    Shouldn't the global template variable just be deleted in python3? It is no longer documented except for what is probably an overlooked mention in the introduction.

    @ericvsmith
    Copy link
    Member

    I sort of agree with David.

    The global "template" is a bad name and a bad design. And since it doesn't work I don't think anything would be lost by modifying the code to ignore it; document that it's unused and deprecated; and remove it in a future version.

    @bitdancer
    Copy link
    Member

    It has been documented as deprecated since 2.0. I'm sure the intent was for all mention of it to have been deleted from the 3.x docs already, but that first paragraph was overlooked.

    @rhettinger
    Copy link
    Contributor

    +1 for just deleting it. nothing is lost by deleting code that never worked in the first place ;-)

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 23, 2011

    New changeset eafe8c7f7049 by R David Murray in branch 'default':
    bpo-10354: remove last public mentions of 'template' and comment as private.
    http://hg.python.org/cpython/rev/eafe8c7f7049

    @bitdancer
    Copy link
    Member

    I have removed the last mentions of template from the docs and docstrings, and added a comment that it is a private variable despite its name. I do not see a reason to break backward compatibility just to have a leading underscore in the name. If there is disagreement on this we can reopen the issue.

    @gpshead
    Copy link
    Member

    gpshead commented May 19, 2015

    backwards compatibility with what? i'd like to just remove tempfile.template in 3.5 as part of addressing bpo-24230.

    @bitdancer
    Copy link
    Member

    Backward compatibility in that someone might be using the constant in their code. You could just leave the existing value there with a comment that it is unused and use a leading _ for the new constants. (Or you could delete it...it's not likely anyone is using it, I just tend to be conservative unless there is motivation to do otherwise.)

    @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
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants