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 — Fully implement IOBase abstract on SpooledTemporaryFile · Issue #70363 · python/cpython

Fully implement IOBase abstract on SpooledTemporaryFile #70363

New issue
Copy link
New issue
Copy link
Closed
Closed
Fully implement IOBase abstract on SpooledTemporaryFile#70363
Copy link
Labels
3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Description

GFernie
mannequin
opened on Jan 21, 2016
Issue body actions
BPO 26175
Nosy @terryjreedy, @giampaolo, @merwok, @pR0Ps, @vadmium, @ztane, @GFernie, @iritkatriel, @danieldjewell, @adriangb
PRs
  • bpo-26175: Fix SpooledTemporaryFile IOBase abstract #3249
  • bpo-26175: Implement io.IOBase interface for SpooledTemporaryFile #29560
  • Files
  • fix-SpooledTemporaryFile-IOBase-abstract.patch: 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 = None
    created_at = <Date 2016-01-21.21:54:34.199>
    labels = ['type-bug', 'library', '3.11']
    title = 'Fully implement IOBase abstract on SpooledTemporaryFile'
    updated_at = <Date 2022-02-28.19:38:17.577>
    user = 'https://github.com/GFernie'

    bugs.python.org fields:

    activity = <Date 2022-02-28.19:38:17.577>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2016-01-21.21:54:34.199>
    creator = 'Gary Fernie'
    dependencies = []
    files = ['41685']
    hgrepos = []
    issue_num = 26175
    keywords = ['patch']
    message_count = 14.0
    messages = ['258769', '258782', '310298', '319089', '319145', '328908', '328911', '368801', '379957', '379958', '413973', '414033', '414035', '414218']
    nosy_count = 11.0
    nosy_names = ['terry.reedy', 'giampaolo.rodola', 'eric.araujo', 'pR0Ps', 'martin.panter', 'ztane', 'Gary Fernie', 'nubirstein', 'iritkatriel', 'danieljewell', 'adriangb']
    pr_nums = ['3249', '29560']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26175'
    versions = ['Python 3.11']

    Activity

    1. GFernie commented on Jan 21, 2016

      @GFernie
      GFerniemannequin
      on Jan 21, 2016
      MannequinAuthor
      More actions

      SpooledTemporaryFile does not fully satisfy the abstract for IOBase.
      Namely, seekable, readable, and writable are missing.

      This was discovered when seeking a SpooledTemporaryFile-backed lzma file.
      You may quickly repro this:
      lzma.open(SpooledTemporaryFile()).seek(0)

    2. GFernie
      added
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Jan 21, 2016
    3. vadmium commented on Jan 22, 2016

      @vadmium
      vadmium
      on Jan 22, 2016
      Member
      More actions

      It would be nice to add test cases for this.

      Looking at <https://docs.python.org/release/3.4.3/library/tempfile.html#tempfile.SpooledTemporaryFile\>, there is a version changed notice for the truncate() method. So perhaps this should be added as a new feature for 3.6. On the other hand, the documentation doesn’t mention the specific API, so I would assume the relevant IOBase subclass, and this would be a bug.

    4. vadmium
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Jan 22, 2016
    5. vadmium commented on Jan 19, 2018

      @vadmium
      vadmium
      on Jan 19, 2018
      Member
      More actions

      It may also be worth implementing BufferedIOBase and TextIOBase. (It seems buffering=0 isn’t reliable, e.g. rollover with limited disk space, so it may not be worth implementing RawIOBase.)

      To implement BufferedIOBase, “read1” and “readinto1” should be added.

      To implement TextIOBase, “errors” should be added, and “newlines” should only list translated newlines, not the “newline” constructor argument.

      Technically, “detach” should also be implemented, although it doesn’t have to do anything useful.

    6. terryjreedy commented on Jun 8, 2018

      @terryjreedy
      terryjreedy
      on Jun 8, 2018
      Member
      More actions

      Martin, the PR has one 'approved' review, not from you. You appear to be requesting changes here, but it is not clear to me which are 'maybe' and which are 'must'.

      It is not obvious to me whether this should be treated as enhancement or behavior issue, but backporting is moot until something is merged into master.

    7. terryjreedy
      added
      3.8 (EOL)end of lifeend of life
      on Jun 8, 2018
    8. vadmium commented on Jun 9, 2018

      @vadmium
      vadmium
      on Jun 9, 2018
      Member
      More actions

      I was making suggestions, not demanding anything. Except for the quirk with __del__, Gary’s changes (revision fb28362) look okay to add on their own as a bug fix.

      I wouldn’t claim that IOBase is “fully implemented” however, until the return values for “seek” and “truncate” are fixed.

      The underlying problem is the original SpooledTemporaryFile imitated Python 2’s file class/type, and wasn’t completely adapted for Python 3’s file classes.

    9. nubirstein commented on Oct 30, 2018

      @nubirstein
      nubirsteinmannequin
      on Oct 30, 2018
      Mannequin
      More actions

      Should I have been added my request there? Anyway I do suffer from lack of 'seekable()' implementation there

    10. nubirstein commented on Oct 30, 2018

      @nubirstein
      nubirsteinmannequin
      on Oct 30, 2018
      Mannequin
      More actions

      My last comment meant to land somewhere else, but nonetheless it is related to this topic, so:

      SpooledTemporaryFile class from lib/tempfile.py still does not implement seekable() method. It could be like this (just two lines of code and my Flask.Request tests with sending files started again to work on 3.7:

          def seekable(self):
              return self._file.seekable()

      Is it possible to add this method?

    11. danieldjewell commented on May 13, 2020

      @danieldjewell
      danieldjewellmannequin
      on May 13, 2020
      Mannequin
      More actions

      To add something additional here:

      The current documentation for tempfile.SpooledTemporaryFile indicates "This function operates exactly as TemporaryFile() does, except that data is spooled in memory until the file size exceeds max_size[...]" (see https://docs.python.org/3/library/tempfile.html)

      Except that SpooledTemporaryFile *doesn't* act _exactly_ like TemporaryFile() - as documented here. TemporaryFile() returns an "_io.BufferedRandom" which implements all of the expected "file-like" goodies - like [.readable, .seekable, ...etc]. SpooledTemporaryFile does not.

      In comparing to the 2.x docs, the text for SpooledTemporaryFile() appears to be identical or nearly identical to the 3.8.x current docs. This goes in line with what has already been discussed here.

      At a _very minimum_ the documentation should be updated to reflect the current differences between TemporaryFile() and SpooledTemporaryFile().

      Perhaps an easier change would be to extend TemporaryFile() to have a parameter that enables functionality similar to SpooledTemporaryFile? Namely, *memory-only* storage up to a max_size? Or perhaps there is an alternate solution that already exists?

      Ultimately, the functionality that appears to be missing is to be able to easily create a file-like object backed primarily by memory for reading/writing data ... (i.e. one 100% compatible with 'the usual' file objects returned by open()...)

    12. ztane commented on Oct 30, 2020

      @ztane
      ztanemannequin
      on Oct 30, 2020
      Mannequin
      More actions

      Another test case:

      import tempfile
      import io
      import json
      
      
      with tempfile.SpooledTemporaryFile(max_size=2**20) as f:
          tf = io.TextIOWrapper(f, encoding='utf-8')
          json.dump({}, fp=tf)

      I was writing json to a file-like object that I need to read in as binary (to upload to S3). Originally the code used BytesIO and I thought it would be wise to actually spool this to disk as I was operating with possible limited RAM... except that of course it didn't work.

    13. ztane commented on Oct 30, 2020

      @ztane
      ztanemannequin
      on Oct 30, 2020
      Mannequin
      More actions

      ... to further clarify, it is disappointing that either BytesIO or TemporaryFile would work alone, but the one that merges these two doesn't.

    14. merwok commented on Feb 25, 2022

      @merwok
      merwok
      on Feb 25, 2022
      Member
      More actions

      I believe the PR is in good shape.
      Can someone with expertise in tempfile review it?

      It would also be useful if the people who had a bug could test the new code.

    15. merwok
      added
      3.11only security fixesonly security fixes
      and removed
      3.8 (EOL)end of lifeend of life
      on Feb 25, 2022
    16. terryjreedy commented on Feb 25, 2022

      @terryjreedy
      terryjreedy
      on Feb 25, 2022
      Member
      More actions

      Éric, you might use git log or git blame to see who that is active has patched the relevant file in the last few years.

    17. terryjreedy commented on Feb 25, 2022

      @terryjreedy
      terryjreedy
      on Feb 25, 2022
      Member
      More actions

      Also, which of the two patches.

      Irit, you just patched Temp file doc, can you look at the PR code?

    18. iritkatriel commented on Feb 28, 2022

      @iritkatriel
      iritkatriel
      on Feb 28, 2022
      Member
      More actions

      Irit, you just patched Temp file doc, can you look at the PR code?

      I don't consider myself and expert here, but I left a comment on PR29560 just to be a good sport.

    19. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    20. methane
      added a commit that references this issue on May 3, 2022

      gh-70363: Implement `io.IOBase` interface for `SpooledTemporaryFile` (G…

      78e70be
    21. methane
      removed
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on May 3, 2022
    22. methane
      closed this as completedon May 3, 2022
    23. tiran
      added 2 commits that reference this issue on May 5, 2022

      pythongh-70363: Emscripten cannot fstat renamed spool file

      954a6d1

      gh-70363: Emscripten cannot fstat renamed spool file (GH-92354)

      49fda0c
    24. ianwal
      added a commit that references this issue on Jul 31, 2023

      Fixed SpooledTemporaryFile on Python <3.11

      64a19ce
    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

      3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

      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.