pappasam / nvim-repl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python Class throws indent error

ECon87 opened this issue · comments

Hi again,

I am trying to create a python class but the following minimum working example throws an indent error.

class LetsCheck():
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def get_area(self):
        return self.x * self.y

The following does not work either.

class LetsCheck():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def get_area(self):
        return self.x * self.y

@ECon87 Would you be able to test out this branch: https://github.com/pappasam/nvim-repl/tree/remove-newlines ? I'm not sure if this will produce any unexpected behavior outside of the example you've provided, so if you can test for a while and confirm that it doesn't do anything you dislike, I can merge after you've had a chance to use it for a while.

Hi @pappasam,

Thank you for the prompt response. The branch solved the original problem for the most part; in the earlier example, I need to manually go the repl and press enter to run the code.

Another issue is that I still get indentation errors in more complicated class definitions. For example, if I call function and place its arguments in separate lines, I still get an indentation error.

Consider the following:

class Reminder():
    def __init__(self, url, loop):
        self.url = url
        self.loop = loop
        Notify.init("Reminder")
        self.SendNotification()

    def SendNotification(self):
        self.n = Notify.Notification.new("Reminder \n Todo")
        self.n.add_action(self.url,
                          "Open Link",
                           self.openURL)
        self.n.show()

Now after self.n.add_action I get an indentation error.

Thank you again for the help and work.

@ECon87 yes, after some experimentation, it looks like my new PR introduces some new problems. In short, this issue is caused by limitations in the default Python repl. If you'd like to reduce these issues, I suggest using bpython (pip install bpython) and configuring it like this (note: I've configured more than just bpython in case you find at useful):

let g:repl_filetype_commands = {
      \ 'bash': 'bash',
      \ 'javascript': 'node',
      \ 'python': 'bpython -q',
      \ 'sh': 'sh',
      \ 'vim': 'nvim --clean -ERZM',
      \ 'zsh': 'zsh',
      \ }

let g:repl_default = &shell

Will close my PR and document the above suggestion in the readme