Skip to content

gh-121711: Set -m asyncio return_code to 1 for ENOTTY #121714

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

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def run(self):
if os.getenv("PYTHON_BASIC_REPL"):
raise RuntimeError("user environment requested basic REPL")
if not os.isatty(sys.stdin.fileno()):
raise OSError(errno.ENOTTY, "tty required", "stdin")
return_code = errno.ENOTTY
raise OSError(return_code, "tty required", "stdin")

# This import will fail on operating systems with no termios.
from _pyrepl.simple_interact import (
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from textwrap import dedent
from test import support
from test.support import cpython_only, has_subprocess_support, SuppressCrashReport
from test.support.script_helper import kill_python, assert_python_ok
from test.support.script_helper import assert_python_failure, kill_python, assert_python_ok
from test.support.import_helper import import_module


Expand Down Expand Up @@ -195,8 +195,8 @@ def bar(x):
expected = "(30, None, [\'def foo(x):\\n\', \' return x + 1\\n\', \'\\n\'], \'<stdin>\')"
self.assertIn(expected, output, expected)

def test_asyncio_repl_is_ok(self):
assert_python_ok("-m", "asyncio")
def test_asyncio_repl_no_tty_fails(self):
assert assert_python_failure("-m", "asyncio")
Copy link
Member

@Eclips4 Eclips4 Jul 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we now know that the asyncio REPL is not working? Initially, test_asyncio_repl_is_ok was added because the asyncio repl is not working on Windows due to a bug.
Additionally: We don't use assert statement in our test suite.

Copy link
Contributor Author

@zvyn zvyn Jul 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the new test passes means that assert_python_ok never tested weather the repl works.

I think t should be testet without setting stdin on Popen (inside assert_python_ok).

I can add that test, but it will fail because of another bug I found and am intending to fix soonish (report pending, easy to reproduce by running python -m asyncio from the main branch).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eclips4 asyncio REPL is currently broken and this wasn't caught.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the new test passes means that assert_python_ok never tested weather the repl works.

I think t should be testet without setting stdin on Popen (inside assert_python_ok).

I can add that test, but it will fail because of another bug I found and am intending to fix soonish (report pending, easy to reproduce by running python -m asyncio from the main branch).

Yes, you're right, I'm also experiencing the problem with python -m asyncio:

./python -m asyncio
asyncio REPL 3.14.0a0 (heads/main:dc03ce797a, Jul 13 2024, 15:05:30) [GCC 13.2.0] on linux
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
TypeError: run_multiline_interactive_console() missing 1 required positional argument: 'namespace'
Internal error, exiting asyncio REPL...



class TestInteractiveModeSyntaxErrors(unittest.TestCase):
Expand Down
Loading