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

sys.stdin has no attribute 'buffer' #1083

Open
mhsmith opened this issue Jan 26, 2024 · 0 comments
Open

sys.stdin has no attribute 'buffer' #1083

mhsmith opened this issue Jan 26, 2024 · 0 comments
Labels
Milestone

Comments

@mhsmith
Copy link
Member

mhsmith commented Jan 26, 2024

As in #516 and #654, some code may ignore the documentation warning that stdin "may be replaced with file-like objects", and assume it's a "regular text file like those returned by the open() function", including buffer and related attributes.

This was discovered by the CPython argparse unit tests:

10:05:43.526  I    File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/stdlib-common.imy/argparse.py", line 2555, in _get_value
10:05:43.526  I      result = type_func(arg_string)
10:05:43.526  I               ^^^^^^^^^^^^^^^^^^^^^
10:05:43.526  I    File "/data/user/0/com.chaquo.python.pkgtest3/files/chaquopy/stdlib-common.imy/argparse.py", line 1309, in __call__
10:05:43.526  I      return _sys.stdin.buffer if 'b' in self._mode else _sys.stdin
10:05:43.526  I             ^^^^^^^^^^^^^^^^^
10:05:43.526  I  AttributeError: 'EmptyInputStream' object has no attribute 'buffer'

As of Python 3.13, the default stdin (sys.__stdin__) returns EOF already, both on emulators with API levels 34 and 21, and the Pixel 7. If this applies to older Python versions too, we can just remove the sys.stdin override and the EmptyInputStream class.

@mhsmith mhsmith changed the title Make sys.stdin a TextIOWrapper sys.stdin has no attribute 'buffer' Apr 16, 2024
@mhsmith mhsmith added bug and removed enhancement labels Apr 16, 2024
@mhsmith mhsmith added this to the 15.1 milestone Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant