Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goto_assignments: does not find correct definition for bs4.BeautifulSoup.find_all #1396

Closed
blueyed opened this issue Sep 12, 2019 · 5 comments
Labels

Comments

@blueyed
Copy link
Contributor

blueyed commented Sep 12, 2019

Given t_bs4.py:

import jedi

source = """
import bs4
soup = bs4.BeautifulSoup()
soup.find_all()
"""

script = jedi.Script(source, 4, 5)

definitions = script.goto_assignments(follow_imports=True)
print(definitions)
print([(x.module_path, x.line, x.column)
       for x in definitions])

Running python t_bs4.py in a virtualenv where "beautifulsoup4==4.8.0" is installed shows:

[<Definition full_name='bs4.BeautifulSoup.find_all', description='def find_all'>]                                                                                                                                    
[('…/.venv/lib/python3.7/site-packages/bs4/__init__.py', 1264, 8)]                                                                                            

However the file has only 616 lines.

The position appears to refer to:

.venv/lib/python3.7/site-packages/bs4/element.py                                                                                                                                                                     
1264:    def find_all(self, name=None, attrs={}, recursive=True, text=None,                                                                                                                                          

This causes an error in jedi-vim then:

'Cursor position outside buffer'

Tried with latest release and master (66022ed).

Reminded me of #1315, which is working though by now.

@blueyed
Copy link
Contributor Author

blueyed commented Sep 12, 2019

class BeautifulSoup(Tag) is defined in __init__.py, but find_all is from class Tag, defined in bs4.element.

So it seems the position is correct (from the parent class), but the module_path is not.

@blueyed
Copy link
Contributor Author

blueyed commented Nov 3, 2019

davidhalter/jedi-vim#962 (comment) appears to have a simpler test case.

@davidhalter
Copy link
Owner

I just answered a similar question on stackoverflow: https://stackoverflow.com/questions/58594395/jedi-python-autocompletions-hints-not-showing-methods-or-suggestions

The problem is basically that the code in bs4.element.Tag._find_all (which is what Soup.find does), is so hard to infer, that Jedi just doesn't understand it. When I'm reading the code, I'm not even quite sure what the return types can be. So how would Jedi understand... Anyway: The solution would be to give the find method an annotation to show what types it returns. It's currently just very unclear what gets returned there.

I don't really think there's a solution for the type inference of this, but we should definitely fix the Cursor position outside buffer.

@davidhalter
Copy link
Owner

I just realized that you didn't even ask about the type inference of find_all(). So just forget my comment, your original issue is still there.

@davidhalter
Copy link
Owner

Very glad that you found this one. It always confused me that jedi-vim sometimes went to the wrong file. For a while I suspected jedi-vim might be the one to blame, but it turns out it was all me ;-)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants