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

AutoImport's get_modules is case insensitive #715

Closed
niqodea opened this issue Oct 27, 2023 · 4 comments
Closed

AutoImport's get_modules is case insensitive #715

niqodea opened this issue Oct 27, 2023 · 4 comments
Labels
bug Unexpected or incorrect user-visible behavior
Milestone

Comments

@niqodea
Copy link

niqodea commented Oct 27, 2023

Describe the bug

AutoImport's get_modules is case insensitive. Not sure if exactly a bug, but I don't think this behavior fits considering the method is used for full names and not for autocompletion purposes.

To Reproduce

from pathlib import Path
from rope.base.project import Project
from rope.contrib.autoimport.sqlite import AutoImport

autoimport = AutoImport(Project(Path()), memory=False)
autoimport.generate_cache()
autoimport.generate_modules_cache()
print(autoimport.get_modules("C"))

The code above prints ['calendar'] but from calendar import C is not a valid import. In fact, the correct symbol is c (lower-case).

The same happens with the pickle version of AutoImport.

Editor information:

  • Project Python version: 3.10.13
  • Rope Python version: 3.10.13
  • Rope version: 1.10.0
  • Text editor/IDE and version: N/A
@niqodea niqodea added the bug Unexpected or incorrect user-visible behavior label Oct 27, 2023
@lieryan
Copy link
Member

lieryan commented Oct 30, 2023

IIUC, this is likely intentional because one of the way autoimport can be used is for adding imports automatically when autocompleting names that aren't in the current scope, this is how autoimport is implemented in pylsp's builtin autoimport for example.

For the use case of autoimport of the symbol under cursor, this behavior might not necessarily be desirable, so it might make sense to make this behavior configurable.

@bagel897 do you have any thoughts on this?

@bagel897
Copy link
Contributor

The method is kept for compatibility with the old API, using exact matches would make sense for this.
I cannot reproduce the same behavior in pickle, only sqllite.
This method isn't used in the pylsp completion engine, so I'll change it to match pickle.

@bagel897 bagel897 mentioned this issue Oct 30, 2023
lieryan added a commit that referenced this issue Oct 30, 2023
@lieryan
Copy link
Member

lieryan commented Oct 30, 2023

@niqodea does #721 fix your issue? If it doesn't, please feel free to re-open the issue.

@niqodea
Copy link
Author

niqodea commented Oct 30, 2023

It works! Thank you so much @bagel897. Looking forward to the new release containing this fix.

@lieryan lieryan added this to the 1.11.0 milestone Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect user-visible behavior
Projects
None yet
Development

No branches or pull requests

3 participants