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

Unsupported IO operations should raise UnsupportedOperation #53539

Closed
pitrou opened this issue Jul 18, 2010 · 4 comments
Closed

Unsupported IO operations should raise UnsupportedOperation #53539

pitrou opened this issue Jul 18, 2010 · 4 comments
Labels
easy stdlib Python modules in the Lib dir topic-IO type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Jul 18, 2010

BPO 9293
Nosy @amauryfa, @pitrou, @vstinner, @benjaminp, @skrah
Files
  • unsupported.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 2010-09-05.23:05:17.250>
    created_at = <Date 2010-07-18.14:09:29.177>
    labels = ['easy', 'type-bug', 'library', 'expert-IO']
    title = 'Unsupported IO operations should raise UnsupportedOperation'
    updated_at = <Date 2010-09-05.23:05:17.249>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2010-09-05.23:05:17.249>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-09-05.23:05:17.250>
    closer = 'pitrou'
    components = ['Library (Lib)', 'IO']
    creation = <Date 2010-07-18.14:09:29.177>
    creator = 'pitrou'
    dependencies = []
    files = ['18733']
    hgrepos = []
    issue_num = 9293
    keywords = ['patch', 'easy']
    message_count = 4.0
    messages = ['110648', '110650', '115490', '115677']
    nosy_count = 6.0
    nosy_names = ['amaury.forgeotdarc', 'pitrou', 'vstinner', 'benjamin.peterson', 'stutzbach', 'skrah']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9293'
    versions = ['Python 3.2']

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 18, 2010

    Some of them currently raise IOError. Fortunately, UnsupportedOperation inherits from IOError, which means compatibility can be preserved.

    Contrast:
    >>> open("LICENSE").write("bar")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IOError: not writable
    
    With:
    >>> open("LICENSE", "rb").write(b"")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    io.UnsupportedOperation: write
    
    Or:
    >>> io.StringIO().fileno()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    io.UnsupportedOperation: fileno

    Or, unfortunately:

    >>> open("LICENSE", "rb", buffering=0).write(b"")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: File not open for writing

    @pitrou pitrou added stdlib Python modules in the Lib dir topic-IO easy type-bug An unexpected behavior, bug, or error labels Jul 18, 2010
    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 18, 2010

    Another kind of unsupported operation is non-absolute seeking on a TextIOWrapper:

    >>> open("LICENSE").seek(1, 1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IOError: can't do nonzero cur-relative seeks

    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 3, 2010

    Here is a patch.

    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 5, 2010

    Committed in r84544.

    @pitrou pitrou closed this as completed Sep 5, 2010
    @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
    easy stdlib Python modules in the Lib dir topic-IO type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant