Charachter 'b' disapears from testers input (shell-python)

Hi! I’m currently on stage #qp2 of ‘Build your own Shell’ and need some help with debugging.

I faced a weird problem where character ‘b’ disappears from input that the tester file inputs into my program. The only piece of my code, that actually interacts with the readline, is the code of my current stage, which is about autocompletion. Before this stage, everything worked fine.

I’ve tried to recreate inputs from tests, by typing/pasting them, but I have not faced any problems with character ‘b’. My code that uses python’s readline, by my evaluation, does nothing more than binding tab to autocompletion, and enabling arrow navigation support on a readline.

Here are my logs:



[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
Debug = true
[tester::#QP2] Running tests for Stage #QP2 (Autocompletion - Builtin completion)
[tester::#QP2] Running ./your_program.sh
[tester::#QP2] ✓ Received prompt ($ )
[tester::#QP2] Typed "ech"
[tester::#QP2] ✓ Prompt line matches "$ ech"
[tester::#QP2] Pressed "<TAB>" (expecting autocomplete to "echo")
[tester::#QP2] ✓ Prompt line matches "echo"
[your-program] $ echo 
[tester::#QP2] Tearing down shell
[tester::#QP2] Running ./your_program.sh
[tester::#QP2] ✓ Received prompt ($ )
[tester::#QP2] Typed "exi"
[tester::#QP2] ✓ Prompt line matches "$ exi"
[tester::#QP2] Pressed "<TAB>" (expecting autocomplete to "exit")
[tester::#QP2] ✓ Prompt line matches "exit"
[your-program] $ exit 
[tester::#QP2] Tearing down shell
[tester::#QP2] Test passed.
[tester::#UN3] Running tests for Stage #UN3 (Redirection - Append stderr)
[tester::#UN3] [setup] export PATH=/tmp/banana/mango/mango:$PATH
[tester::#UN3] Running ./your_program.sh
[your-program] $ ls -1 nonexistent >> /tmp/owl/ee.md
[tester::#UN3] ^ Line does not match expected value.
[tester::#UN3] Expected: "$ ls -1 nonexistent >> /tmp/owl/bee.md"
[tester::#UN3] Received: "$ ls -1 nonexistent >> /tmp/owl/ee.md"
[your-program] ls: nonexistent: No such file or directory
[your-program] $ 
[tester::#UN3] Assertion failed.
[tester::#UN3] Test failed

And here’s a snippet of my code:

   #  --------------------------------------------------
#   AUTOCOMPLETION

    def readlineSet(self):
        readline.parse_and_bind('set editing-mode vi') 
        readline.set_completer(self.complete)
        readline.parse_and_bind('bind ^I rl_complete')

    def complete(self, string, state):
        const_options = ['echo', 'exit']
        const_options = [option for option in const_options if string in option]
        if(string == const_options[state][:-1]):
            return const_options[state] + ' '
        else:
            return None
        

   #  --------------------------------------------------

    def main(self):

        self.readlineSet()

        # REPL
        while(True):
            self.userInput = ''


            self.userInput = input("$ ")
             
            if(self.userInput == ''):
                continue
            userInputSplit = formatting.formatInput(self.userInput)
            self.outRedirectFlag = False
            self.errRedirectFlag = False
            self.outputList = []
            self.errList = []
            if('1>' in userInputSplit  or '1>>' in userInputSplit):
                self.outRedirectFlag = True
            if('2>' in userInputSplit or '2>>' in userInputSplit):
                self.errRedirectFlag = True
            executeOutput = self.execute(userInputSplit)



if __name__ == '__main__':
    newShell = Shell()
    newShell.main()

Here is my git-repo with full code:
https://github.com/Finyti/codecrafters-shell-python/tree/main

Thanks in advance!

Hey @Finyti, the issue stems from this line. Removing it should fix the problem:

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.