Skip to content

Commit 3fa01f2

Browse files
committed
fix: init dataclass Console init with value ignore repr error
Signed-off-by: yihong0618 <[email protected]>
1 parent 89b5571 commit 3fa01f2

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Lib/_pyrepl/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class Event:
4747

4848
@dataclass
4949
class Console(ABC):
50-
posxy: tuple[int, int]
51-
screen: list[str] = field(default_factory=list)
50+
posxy: tuple[int, int] = field(default=(0, 0), repr=False)
51+
screen: list[str] = field(default_factory=list, repr=False)
5252
height: int = 25
5353
width: int = 80
5454

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,26 @@ def test_dumb_terminal_exits_cleanly(self):
14141414
self.assertNotIn("Traceback", output)
14151415

14161416

1417+
class TestConsoleRepr(TestCase):
1418+
1419+
def test_console_repr_with_missing_attributes(self):
1420+
from _pyrepl.unix_console import UnixConsole
1421+
console = UnixConsole()
1422+
1423+
repr_str = repr(console)
1424+
1425+
self.assertIsInstance(repr_str, str)
1426+
self.assertIn("UnixConsole", repr_str)
1427+
1428+
def test_readline_wrapper_repr_after_import(self):
1429+
import _pyrepl.readline
1430+
1431+
wrapper = _pyrepl.readline._wrapper
1432+
if wrapper is not None and wrapper.reader is not None:
1433+
repr_str = repr(wrapper.reader)
1434+
self.assertIsInstance(repr_str, str)
1435+
1436+
14171437
@skipUnless(pty, "requires pty")
14181438
@skipIf((os.environ.get("TERM") or "dumb") == "dumb", "can't use pyrepl in dumb terminal")
14191439
class TestMain(ReplTestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix: make dataclass Console init right to avoid has no attribute 'posxy'
2+
error

0 commit comments

Comments
 (0)