Skip to content

IDLE - sys.stdin is writeable #59523

Closed
Closed

Description

@serwy
mannequin
BPO 15318
Nosy @loewis, @terryjreedy, @serwy, @serhiy-storchaka
Files
  • blockwrite.diff
  • blockwrite.diff
  • idle_stdstreams-2.patch
  • idle_stdstreams-3.patch
  • blockfile-3.diff
  • blockfile-4.diff
  • 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 2012-07-25.08:57:02.216>
    created_at = <Date 2012-07-10.14:13:24.084>
    labels = ['expert-IDLE', 'type-bug']
    title = 'IDLE - sys.stdin is writeable'
    updated_at = <Date 2012-07-25.08:57:02.215>
    user = 'https://github.com/serwy'

    bugs.python.org fields:

    activity = <Date 2012-07-25.08:57:02.215>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-07-25.08:57:02.216>
    closer = 'loewis'
    components = ['IDLE']
    creation = <Date 2012-07-10.14:13:24.084>
    creator = 'roger.serwy'
    dependencies = []
    files = ['26350', '26351', '26353', '26354', '26361', '26362']
    hgrepos = []
    issue_num = 15318
    keywords = ['patch']
    message_count = 25.0
    messages = ['165190', '165215', '165216', '165230', '165231', '165232', '165240', '165241', '165242', '165245', '165249', '165251', '165259', '165260', '165269', '165271', '165274', '165277', '165291', '165292', '165307', '165316', '165319', '166368', '166369']
    nosy_count = 5.0
    nosy_names = ['loewis', 'terry.reedy', 'roger.serwy', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue15318'
    versions = ['Python 2.7', 'Python 3.3']

    Activity

    1. serwy commented on Jul 10, 2012

      serwymannequin
      MannequinAuthor

      This is a follow-up to bpo-13532 which fixed problems with IDLE's sys.stdout and sys.stderr implementation.

      Presently, sys.stdin has a write method, but does not raise "io.UnsupportedOperation: not writable" when passed a string. Instead, it writes to the IDLE shell.

    2. added
      type-bug
      on Jul 10, 2012
    3. terryjreedy commented on Jul 11, 2012

      @terryjreedy
      Member

      To me, this is part of bpo-15319. sys.stdin is broken in being writable but not readable. Unwrapping is just the first, trivial step to fixing it. So I think we should close this in favor of the other.

    4. serwy commented on Jul 11, 2012

      serwymannequin
      MannequinAuthor

      I agree. I'll close it.

    5. loewis commented on Jul 11, 2012

      loewismannequin
      Mannequin

      It's *clearly* not a duplicate. While bpo-15319 is fixed, this issue remains - so it can't possibly be a duplicate.

    6. reopened this on Jul 11, 2012
    7. loewis commented on Jul 11, 2012

      loewismannequin
      Mannequin

      I propose the attached patch to block write() calls.

    8. loewis commented on Jul 11, 2012

      loewismannequin
      Mannequin

      Revised

    9. serhiy-storchaka commented on Jul 11, 2012

      @serhiy-storchaka
      Member

      sys.std* streams have many other issues.

      >>> sys.stdin.readable()
      Traceback (most recent call last):
        File "<pyshell#4>", line 1, in <module>
          sys.stdin.readable()
      AttributeError: readable
      >>> sys.stdout.writable()
      Traceback (most recent call last):
        File "<pyshell#5>", line 1, in <module>
          sys.stdout.writable()
      AttributeError: writable
      >>> sys.stdout.newlines
      Traceback (most recent call last):
        File "<pyshell#8>", line 1, in <module>
          sys.stdout.newlines
      AttributeError: newlines
      >>> sys.stdin.read(1)
      Traceback (most recent call last):
        File "<pyshell#3>", line 1, in <module>
          sys.stdin.read(1)
      AttributeError: read

      And some other.

      Here is a patch that fixes almost all IDLE sys.std* issues.

    10. serhiy-storchaka commented on Jul 11, 2012

      @serhiy-storchaka
      Member

      Added getvar method to PyShell.console.

    11. loewis commented on Jul 11, 2012

      loewismannequin
      Mannequin

      Serhiy: can you please explicitly list what issues your patch fixes?

      I can think of many *more* issues that your patch doesn't fix, e.g. sys.stdin.read(sys) and sys.stdout.read().

      I'm quite opposed to monkey-patching, so I won't commit any patch that involves monkey-patching (i.e. _checked_text_writer). I'm also unsure what problem this change to monkey-patching solves: I believe the current code is fine in this respect as it stands.

      Before you grow the patch to add many more lines of code, please try to stick to the "one issue at a time" principle. As a guideline: if you need to write additional lines of code, it's a separate issue.

    12. loewis commented on Jul 11, 2012

      loewismannequin
      Mannequin

      As an additional note: the change to monkey-patching breaks the test

      isinstance(sys.stdout, io.TextIOBase)

      which currently succeeds.

    13. serhiy-storchaka commented on Jul 11, 2012

      @serhiy-storchaka
      Member

      Serhiy: can you please explicitly list what issues your patch fixes?

      bpo-12967. And sys.std* in IDLE lacks other common sys.std* methods and
      attributes.

      I can think of many *more* issues that your patch doesn't fix, e.g. sys.stdin.read(sys) and sys.stdout.read().

      sys.stdin.read(sys) and sys.stdout.read() should not work.

      I'm quite opposed to monkey-patching, so I won't commit any patch that involves monkey-patching (i.e. _checked_text_writer). I'm also unsure what problem this change to monkey-patching solves: I believe the current code is fine in this respect as it stands.

      I introduced _checked_text_writer, because the implementation of
      _RPCFile was broken (I wrote this patch last evening and debug it this
      morning). In addition, _RPCFile is a wrapper around RPCFile, which
      itself is a wrapper. There are too many layers for me. If you are sure
      that the current implementation of _RPCFile is correct, it is not
      necessary.

      Before you grow the patch to add many more lines of code, please try to stick to the "one issue at a time" principle.

      In IDLE sys.std* bad mimic text streams -- this is one issue.

    14. 1 remaining item

    15. serhiy-storchaka commented on Jul 11, 2012

      @serhiy-storchaka
      Member

      bpo-9290 also has relation to this.

    16. serhiy-storchaka commented on Jul 11, 2012

      @serhiy-storchaka
      Member

      bpo-7163 is another PseudoFile-related issue.

    17. loewis commented on Jul 11, 2012

      loewismannequin
      Mannequin

      "implements textio badly" is *not* a well-defined issue.

      First it is a personal judgement: some think it's really bad, some think it's quite ok.

      More importantly, such issue has no clear success criterion: how do we know we are done - can we hope to EVER close such an issue? No, because somebody might still find bad behavior. An issue absolutely needs anobjective test to determine whether it is resolved, and to reproduce it, this is not negotiable. "it behaves badly" provides no test.

      In any case,this issue is about sys.stdin being writable.

      Any objection to checking in my patch?

    18. serhiy-storchaka commented on Jul 11, 2012

      @serhiy-storchaka
      Member

      In any case,this issue is about sys.stdin being writable.

      I already got confused with all these closing/reopening/renaming of
      issues and floating code. Should I open my own issue even if it
      duplicates and supersedes some other?

      Any objection to checking in my patch?

      It does not fixes the issue. sys.stdin.writelines does not raise
      exception.

      Inheritance input file from output file looks very strange.
      _RPCInputFile unnecessary, if redirect stdin not on PyShell self, but on
      PyShell.stdin.

    19. loewis commented on Jul 11, 2012

      loewismannequin
      Mannequin

      I already got confused with all these closing/reopening/renaming of
      issues and floating code. Should I open my own issue even if it
      duplicates and supersedes some other?

      I personally think it would be best if these issues where closed
      *first*, and only then you submit a patch to fix any remaining issues.

      > Any objection to checking in my patch?

      It does not fixes the issue. sys.stdin.writelines does not raise
      exception.

      Ah. See blockfiles-3.diff then.

      Inheritance input file from output file looks very strange.

      Where do you see that? In my patch, _RPCInputFile inherits from
      _RPCFile, which is neither output nor input. Instead, _RPCOutputFile
      also inherits from _RPCFile.

      _RPCInputFile unnecessary, if redirect stdin not on PyShell self, but on
      PyShell.stdin.

      It is necessary, as rpc will not communicate the exceptions properly.

    20. serwy commented on Jul 12, 2012

      serwymannequin
      MannequinAuthor

      I tested blockfile-3.diff against the latest code in the repository.

      sys.stdin.write returns the wrong error message when passed a non-string. Presently it returns io.UnsupportedOperation instead of TypeError: must be str, not ...

      The attached blockfile-4.diff incorporates blockfile-3 and creates a decorator in _RPCFile to ensure the argument is a string and applies it to the _RPCInputFile and _RPCOutputFile write methods.

      A simpler alternative would be duplicating the string check code in _RPCInputFile before the raise statement.

    21. serhiy-storchaka commented on Jul 12, 2012

      @serhiy-storchaka
      Member

      Ah. See blockfiles-3.diff then.

      Well, I have no objections. Patch fixes this issue.

      Where do you see that? In my patch, _RPCInputFile inherits from
      _RPCFile, which is neither output nor input. Instead, _RPCOutputFile
      also inherits from _RPCFile.

      I made a mistake. I mean PseudoInputFile, but it just monkey-patched.

      > _RPCInputFile unnecessary, if redirect stdin not on PyShell self, but on
      > PyShell.stdin.
      It is necessary, as rpc will not communicate the exceptions properly.

      Yes, this is yet another issue. Rpc not communicates properly only
      OSError. Remove "except socket.error: raise" in SocketIO.localcall in
      Lib/idlelib/rpc.py and io.UnsupportedOperation will transparently
      transfered.

    22. serhiy-storchaka commented on Jul 12, 2012

      @serhiy-storchaka
      Member

      sys.stdin.write returns the wrong error message when passed a non-string. Presently it returns io.UnsupportedOperation instead of TypeError: must be str, not ...

      It's not a bug. sys.stdin.write raises io.UnsupportedOperation in
      standard interpreter.

    23. serwy commented on Jul 12, 2012

      serwymannequin
      MannequinAuthor

      On 07/12/2012 04:13 AM, Serhiy Storchaka wrote:

      Serhiy Storchaka<storchaka@gmail.com> added the comment:

      > sys.stdin.write returns the wrong error message when passed a non-string. Presently it returns io.UnsupportedOperation instead of TypeError: must be str, not ...
      It's not a bug. sys.stdin.write raises io.UnsupportedOperation in
      standard interpreter.

      Here's what I get from the standard interpreter:

           Python 3.3.0b1 (default:4752fafb579d, Jul 11 2012, 22:05:03)
           [GCC 4.5.2] on linux
           Type "help", "copyright", "credits" or "license" for more information.
       >>> import sys
       >>> sys.stdin.write(123)
           Traceback (most recent call last):
             File "<stdin>", line 1, in <module>
           TypeError: must be str, not int
       >>>

      ----------


      Python tracker<report@bugs.python.org>
      <http://bugs.python.org/issue15318\>


    24. serhiy-storchaka commented on Jul 12, 2012

      @serhiy-storchaka
      Member
      >>> sys.stdin.write('qwe')
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      io.UnsupportedOperation: not writable
    25. serwy commented on Jul 12, 2012

      serwymannequin
      MannequinAuthor
      >>>> sys.stdin.write('qwe')
      > Traceback (most recent call last):
      >    File "<stdin>", line 1, in<module>
      > io.UnsupportedOperation: not writable
      >
      > 

      I'm passing a number, *not* a string.

    26. python-dev commented on Jul 25, 2012

      python-devmannequin
      Mannequin

      New changeset a82fd35e28be by Martin v. Löwis in branch '3.2':
      Issue bpo-15318: Prevent writing to sys.stdin.
      http://hg.python.org/cpython/rev/a82fd35e28be

    27. python-dev commented on Jul 25, 2012

      python-devmannequin
      Mannequin

      New changeset fa7d4ecc6357 by Martin v. Löwis in branch '2.7':
      Issue bpo-15318: Prevent writing to sys.stdin.
      http://hg.python.org/cpython/rev/fa7d4ecc6357

    28. transferred this issue fromon Apr 10, 2022
    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

      topic-IDLEtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions