Skip to content

python -m pyrepl.completing_reader fails #38

Open
@blueyed

Description

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "…/src/pyrepl/pyrepl/completing_reader.py", line 286, in <module>
    test()
  File "…/src/pyrepl/pyrepl/completing_reader.py", line 276, in test
    reader = TestReader()
TypeError: __init__() missing 1 required positional argument: 'console'

The following patch fixes it (based on

def test():
from pyrepl.unix_console import UnixConsole
reader = HistoricalReader(UnixConsole())
):

diff --git i/pyrepl/completing_reader.py w/pyrepl/completing_reader.py
index 6039688..1e456cc 100644
--- i/pyrepl/completing_reader.py
+++ w/pyrepl/completing_reader.py
@@ -265,13 +265,15 @@ def get_completions(self, stem):
 
 
 def test():
+    from pyrepl.unix_console import UnixConsole
+
     class TestReader(CompletingReader):
         def get_completions(self, stem):
             return [s for l in self.history
                     for s in l.split()
                     if s and s.startswith(stem)]
 
-    reader = TestReader()
+    reader = TestReader(UnixConsole())
     reader.ps1 = "c**> "
     reader.ps2 = "c/*> "
     reader.ps3 = "c|*> "

But then using e.g. Up crashes:

% python -m pyrepl.completing_reader
c**> Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "…/src/pyrepl/pyrepl/completing_reader.py", line 286, in <module>
    test()
  File "…/src/pyrepl/pyrepl/completing_reader.py", line 281, in test
    while reader.readline():
  File "…/src/pyrepl/pyrepl/reader.py", line 605, in readline
    self.handle1()
  File "…/src/pyrepl/pyrepl/reader.py", line 588, in handle1
    self.do_cmd(cmd)
  File "…/src/pyrepl/pyrepl/reader.py", line 535, in do_cmd
    cmd.do()
  File "…/src/pyrepl/pyrepl/commands.py", line 210, in do
    if r.historyi > 0:
AttributeError: 'TestReader' object has no attribute 'historyi'

Not sure how useful (the test/__main__ in) completing_reader.py is in the end though..

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions