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 — Exception using fileinput.hook_compressed in binary mode · Issue #101961 · python/cpython

Exception using fileinput.hook_compressed in binary mode #101961

New issue
Copy link
New issue
Copy link
Closed
Closed
Exception using fileinput.hook_compressed in binary mode#101961
Copy link
Assignees
corona100x1306e6d
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@gmacon
gmacon
opened on Feb 16, 2023
Issue body actions

Bug report

When using the fileinput.hook_compressed hook in binary mode in the case that the file is not compressed, an exception is raised instead of processing the file like normal.

# fileinput_cat.py

import fileinput
import sys

with fileinput.input(mode='rb', openhook=fileinput.hook_compressed) as f:
    for line in f:
        sys.stdout.buffer.write(line)
$ python3.10 fileinput_cat.py fileinput_cat.py
Traceback (most recent call last):
  File "fileinput_bug.py", line 5, in <module>
    for line in f:
  File ".../lib/python3.10/fileinput.py", line 256, in __next__
    line = self._readline()
  File ".../lib/python3.10/fileinput.py", line 385, in _readline
    self._file = self._openhook(self._filename, self._mode)
  File ".../lib/python3.10/fileinput.py", line 432, in hook_compressed
    return open(filename, mode, encoding=encoding, errors=errors)
ValueError: binary mode doesn't take an encoding argument

Your environment

I tried this on Python 3.10.9 (installed from nixpkgs) on Intel macOS 11.7.3. It was working on Python 3.9.16.

Linked PRs

  • gh-101961 fileinput.hookcompressed should not set the encoding value for the binary mode #102068
  • [3.11] gh-101961 fileinput.hookcompressed should not set the encoding value for the binary mode (gh-102068) #102098
  • [3.10] gh-101961 fileinput.hookcompressed should not set the encoding value for the binary mode (gh-102068) #102099

Activity

  1. gmacon
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Feb 16, 2023
  2. arhadthedev
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-IO
    on Feb 17, 2023
  3. corona10
    self-assigned this
    on Feb 18, 2023
  4. corona10 commented on Feb 18, 2023

    @corona10
    corona10
    on Feb 18, 2023
    Member
    More actions

    I will take the issue as the internal OSS sprint for the new contributors.
    I will delegate the issue to my mentees.
    Thanks for understanding!

  5. 0x1306e6d commented on Feb 20, 2023

    @0x1306e6d
    0x1306e6d
    on Feb 20, 2023
    Contributor
    More actions

    I'm looking this issue 👀

  6. corona10
    assigned
    0x1306e6d
    on Feb 20, 2023
  7. 0x1306e6d
    added 2 commits that reference this issue on Feb 20, 2023

    pythongh-101961 Do not pass encoding if binary mode

    79eaa09

    pythongh-101961 Update `Misc/ACKS`

    a1121ea
  8. corona10
    added a commit that references this issue on Feb 21, 2023

    gh-101961 fileinput.hookcompressed should not set the encoding value …

    6f25657
  9. miss-islington
    added 2 commits that reference this issue on Feb 21, 2023

    pythongh-101961 fileinput.hookcompressed should not set the encoding …

    16204f7

    pythongh-101961 fileinput.hookcompressed should not set the encoding …

    f8aabb5
  10. corona10
    added 2 commits that reference this issue on Feb 21, 2023

    [3.10] gh-101961 fileinput.hookcompressed should not set the encoding…

    d9dce23

    [3.11] gh-101961 fileinput.hookcompressed should not set the encoding…

    5bc6927
  11. corona10 commented on Feb 21, 2023

    @corona10
    corona10
    on Feb 21, 2023
    Member
    More actions

    Thank you @ghkim3221 for the hard work!

    Reacted by George Macon
  12. corona10
    closed this as completedon Feb 21, 2023
  13. carljm
    added a commit that references this issue on Feb 23, 2023

    Merge branch 'main' into lockfreecp

    b257a16
  14. python-sidebar
    added 2 commits that reference this issue on Sep 1, 2024

    pythongh-101961 fileinput.hookcompressed should not set the encoding …

    b4a1ade

    pythongh-101961 fileinput.hookcompressed should not set the encoding …

    01f915a
  15. JelleZijlstra
    added a commit that references this issue on Sep 10, 2024

    pythongh-101961 fileinput.hookcompressed should not set the encoding …

    2899955
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @0x1306e6d
    0x1306e6d
  • @corona10
    corona10

Labels

stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

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.