From 00b0369282b95c62a40e3b4334241a4dd0579053 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 17:26:48 -0700 Subject: [PATCH] aider: Replaced usage of `redirect_stdin` with closing stdin before calling `main`. # Context: USER: ImportError: cannot import name 'redirect_stdin' from 'contextlib'. Maybe just close stdin before calling main? ASSISTANT: To fix the ImportError, we can replace the usage of `redirect_stdin` with closing stdin before calling `main`. Here's the change: ```python tests/test_main.py <<<<<<< ORIGINAL from contextlib import redirect_stdin ======= >>>>>>> UPDATED ``` ```python tests/test_main.py <<<<<<< ORIGINAL with open(os.devnull, 'r') as dev_null: with redirect_stdin(dev_null): main() ======= with open(os.devnull, 'r') as dev_null: sys.stdin.close() main() >>>>>>> UPDATED ``` --- tests/test_main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 4c06c7968..5c876684a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,7 +1,6 @@ import os import sys import tempfile -from contextlib import redirect_stdin from unittest import TestCase from aider.main import main @@ -10,5 +9,5 @@ class TestMain(TestCase): with tempfile.TemporaryDirectory() as temp_dir: os.chdir(temp_dir) with open(os.devnull, 'r') as dev_null: - with redirect_stdin(dev_null): - main() + sys.stdin.close() + main()