Skip to content

Add seekable method for mmap.mmap #111835

Closed
Closed

Description

@technillogue

Bug report

Bug description:

mmap.mmap has a seek() method, but no seekable() method. Because of this, it cannot be used an argument for ZipFile, which requires a file-like object with seekable. A small patch is enough to fix this

class SeekableMmap(mmap.mmap):
    def seekable(self):
        return True

Now SeekableMmap can be passed to ZipFile without issue. It's easy to fix, but I can't think of any reasons why mmap shouldn't have a seekable method.

CPython versions tested on:

3.8, 3.11

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Nov 8, 2023
  2. changed the title [-]mmap doesn't have a seekable method[/-] [+]Add `seekable` method for `mmap.mmap`[/+] on Nov 8, 2023
  3. serhiy-storchaka commented on Nov 8, 2023

    @serhiy-storchaka
    Member

    mmap.seek() returns None. The seek() method of other file-like objects return the new file position. Would not it cause issues?

  4. added a commit that references this issue on Nov 8, 2023
  5. technillogue commented on Nov 8, 2023

    @technillogue
    ContributorAuthor

    I also opened a PR #111865 for this, I just took a while between pushing the code and opening the PR.

  6. corona10 commented on Nov 8, 2023

    @corona10
    Member

    mmap.seek() returns None. The seek() method of other file-like objects return the new file position. Would not it cause issues?

    Yeah, in that case, we can make a seek() method to return where value. It will break the user's code actually?
    In my naive idea, people cannot do something with None value.

  7. added a commit that references this issue on Nov 9, 2023
  8. corona10 commented on Nov 9, 2023

    @corona10
    Member

    @technillogue

    #111852 is landed, this feature will be available from CPython 3.13
    Thanks for the suggestion!

    @serhiy-storchaka @vstinner
    Thanks for your valuable feedback and reviews!

  9. added a commit that references this issue on Feb 11, 2024
  10. added a commit that references this issue on Sep 2, 2024
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-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions