ColinKennedy / vim-textobj-block-party

A Vim plugin that selects blocks of Python code
MIT License
9 stars 1 forks source link

Python3 TypeError: '>' not supported between instances of 'str' and 'int' #4

Closed kiryph closed 5 years ago

kiryph commented 6 years ago

I wanted to try out your plugin:

I checked out your issues-1-python3-compatibility branch.

However, pressing daB returns following error

Error detected while processing function 34[2]..<SNR>86_select_function_wrapper[3]..vim_block_party#around_deep:
line    6:
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/Users/kiryph/.vim/pack/minpac/start/vim-textobj-block-party/pythonx/vim_textobj_block_party/party.py", line 96, in around_deep
    boundary = _get_buffer_context(extra_lines=True, search=search, two_way=two_way)
  File "/Users/kiryph/.vim/pack/minpac/start/vim-textobj-block-party/pythonx/vim_textobj_block_party/party.py", line 48, in _get_buffer_conte
xt
    column = max(column, columnwise.find_best_column(previous_lines))
TypeError: '>' not supported between instances of 'str' and 'int' 
ColinKennedy commented 6 years ago

This and the other ticket highlight the need for Python 3 unittests. I'll start with Python 3.6 and 3.7 sometime tonight

kiryph commented 6 years ago

Great to hear. I am looking forward to python3 support.

Precompiled Macvim can only dynamically load python2 or python3. For instance, the new 'dark-powered' plugins from shougo (in particular deoplete & denite) are only python3.

ColinKennedy commented 5 years ago

I built a suite for Python 2.7, 3.4-7 and all of the unittests now pass. The unittests only cover vanilla Python though (nothing vim-related) so I'm willing to bet that the fault is there.

I added a new PR which should fix the issue. Can you try out the new issues-4-str_and_int_mismatch and let me know if that fixes your issue? If not, please post the snippet of code that causes an error so I can reproduce it

kiryph commented 5 years ago

The reported error has disappeared.

However, a new error occured.

My minimal setup looks like

~/.vim
❯ tree -L 5
.
├── pack
│   └── ColinKennedy
│       └── start
│           ├── vim-textobj-block-party
│           │   ├── LICENSE
│           │   ├── README.md
│           │   ├── TODO.md
│           │   ├── autoload
│           │   ├── doc
│           │   ├── ftplugin
│           │   └── pythonx
│           └── vim-textobj-user
│               ├── Gemfile
│               ├── README.md
│               ├── Rakefile
│               ├── autoload
│               ├── doc
│               └── t
└── vimrc

12 directories, 7 files

~/.vim/pack/ColinKennedy/start/vim-textobj-block-party
❯ git status
On branch issues-4-str_and_int_mismatch
Your branch is up to date with 'remotes/origin/issues-4-str_and_int_mismatch'.

nothing to commit, working tree clean

❯ cat ~/demo.py
for index in range(10):
    if index in self.thing:
        print('breaking')

        run_something()

        break
else:
    print('Did not break')

Pressing on the first line dab returns now:

Error detected while processing function 7[2]..<SNR>29_select_function_wrapper[3]..vim_block_party#around_shallow:
line    6:
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/Users/kiryph/.vim/pack/ColinKennedy/start/vim-textobj-block-party/pythonx/vim_textobj_block_party/party.py", line 132, in around_shallow
    boundary = _get_buffer_context(extra_lines=True, search=search, two_way=two_way, customize=False)
  File "/Users/kiryph/.vim/pack/ColinKennedy/start/vim-textobj-block-party/pythonx/vim_textobj_block_party/party.py", line 57, in _get_buffer_context
    customize=customize,
  File "/Users/kiryph/.vim/pack/ColinKennedy/start/vim-textobj-block-party/pythonx/vim_textobj_block_party/block_party/party.py", line 382, in get_boundary
    node = get_nearest_class(code, row, column, classes)
  File "/Users/kiryph/.vim/pack/ColinKennedy/start/vim-textobj-block-party/pythonx/vim_textobj_block_party/block_party/party.py", line 297, in get_nearest_class
    leaf = get_leaf(graph, row, column)
  File "/Users/kiryph/.vim/pack/ColinKennedy/start/vim-textobj-block-party/pythonx/vim_textobj_block_party/block_party/party.py", line 257, in get_leaf
    leaf = graph.get_leaf_for_position((row, column))
  File "/usr/local/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/parso/tree.py", line 310, in get_leaf_for_position
    raise ValueError('Please provide a position that exists within this node.')
ValueError: Please provide a position that exists within this node.
Press ENTER or type command to continue

And moving the cursor to the second line, pressing one of dab\daB\dAb\dAB leaves the line

    print('Break never executed') 

I think this is not what you had in mind.

ColinKennedy commented 5 years ago

Hi kiryph,

I finally got some time again to look into this and replicated the behavior that you are seeing. Your most recent posts highlights two things:

  1. Pressing on the first line dab returns (Traceback)

That message is actually parso + block party doing what is expected. I mentioned it in reddit ( assuming you're the same https://www.reddit.com/user/kiryph :) )

but your cursor does have to be inside of the block for block party to do its thing. That said, I think it's reasonable to make an exception for if there is only one block in the file. Tracebacks aren't exactly confidence-inspiring, after all.

  1. And moving the cursor to the second line

Yep, that's a definite bug. I logged that in this issue: https://github.com/ColinKennedy/vim-textobj-block-party/issues/3

I'll get to work on both and let you know once it's ready.

ColinKennedy commented 5 years ago

The issue that you posted a traceback is fixed.

The other issue where the last part of the block is addressed already in https://github.com/ColinKennedy/vim-textobj-block-party/issues/3 so I'm closing this ticket now.

Please re-open if you continue to have any issues running Block Party using Python 3