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

Advice on fixing attrs import quick-fix #5388

Closed
Tinche opened this issue Jan 23, 2024 · 4 comments
Closed

Advice on fixing attrs import quick-fix #5388

Tinche opened this issue Jan 23, 2024 · 4 comments
Assignees

Comments

@Tinche
Copy link

Tinche commented Jan 23, 2024

Howdy.

I'm one of the maintainers of the attrs library and avid VS Code user. When attempting to auto-import the define attrs function, the quick fix popup suggests importing it from the attr package, instead of from attrs.

The attrs library contains two packages, attr and attrs. The attr package, while not deprecated, is legacy at this point. define is part of our next-gen API, and ideally the suggestion would be to import it from attrs instead. (The same goes for some other symbols, like frozen and field.)

What can we do to make this better, either on our side (maybe it's a packaging issue?) or on yours?

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jan 23, 2024
@debonte
Copy link
Contributor

debonte commented Feb 2, 2024

@heejaechang is the expert here, and may correct me. But I believe that this is because when our indexer finds aliases, it will deduplicate them down to the one "best" location. We'll choose the one with the shortest module path (shortest in terms of levels). When the length is the same, as in this case where attr and attrs have the same number of levels (1), we choose the non-alias declaration, which in this case is attr.

Assuming I'm correct, you could fix this on your side by making attr.define an alias of attrs.define instead of the other way around. But I'm guessing that inverting that relationship would not be trivial.

We recently special-cased the symbols that are both in typing and collections.abc so both are shown. I don't think we want to do that for 3rd party packages though, as it would be a maintenance headache.

It would be nice if package authors could control this somehow, but I don't have any good ideas.

@debonte debonte removed the needs repro Issue has not been reproduced yet label Feb 2, 2024
@Tinche
Copy link
Author

Tinche commented Feb 2, 2024

Assuming I'm correct, you could fix this on your side by making attr.define an alias of attrs.define instead of the other way around. But I'm guessing that inverting that relationship would not be trivial.

Interesting. I'm going to talk to Hynek and see if we can do this.

Thanks for the info @debonte !

@debonte
Copy link
Contributor

debonte commented Feb 2, 2024

Ok, but I want to clarify that this deduplication approach is just Pylance's convention. Other language servers (ex. PyCharm) may behave differently.

@Tinche
Copy link
Author

Tinche commented Feb 4, 2024

I got the boss to accept this change!

Ok, but I want to clarify that this deduplication approach is just Pylance's convention. Other language servers (ex. PyCharm) may behave differently.

Sure, but I use VS Code and I really wanted to scratch this itch ;)

@Tinche Tinche closed this as completed Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants