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

[Feature Request] Nudge new users away from calling dunder methods directly #2616

Open
1 task done
melodyogonna opened this issue May 11, 2024 · 2 comments
Open
1 task done
Labels
enhancement New feature or request Initiative: LSP mojo-repo Tag all issues with this label

Comments

@melodyogonna
Copy link

melodyogonna commented May 11, 2024

Review Mojo's priorities

What is your request?

Is it possible for Mojo tooling like the LSP or compiler to nudge new users away from directly calling dunder methods by providing some diagnostic or warning?

What is your motivation for this change?

It's becoming obvious that new users without previous experience using Python do not understand how dunder methods work, nor how they fit into the language. It would be helpful if these new users were nudged into using dunder methods correctly.

Any other details?

You can check this video to see an example of what I'm talking about - https://youtu.be/mB_1SQlS_B0?si=KtpRjsYsJsxQfBpH&t=250

@melodyogonna melodyogonna added enhancement New feature or request mojo-repo Tag all issues with this label labels May 11, 2024
@JoeLoser JoeLoser added the mojo-tooling Tag for all issues related to repl, lldb, lsp, vscode extension. label May 11, 2024
@soraros
Copy link
Contributor

soraros commented May 11, 2024

Ideas:

  • De-emphasise them by sort them after ordinary methods in auto-completion.
    fn a()
    fn b()
    fn _a()
    fn __init__()
  • Only show them in auto-completion if two leading underscores are present in the current "word buffer". Actually, we could apply the same rules to "private" methods (_*/__*).
    • _i shouldn't match __init__
    • init__ shouldn't match __init__
    • __ should match __init__

@nmsmith
Copy link
Contributor

nmsmith commented May 11, 2024

I would expect all accessible members of a struct to be displayed in auto-complete after you type the .. This allows you to browse the API of a type. Hiding some of the members would obscure the API.

But I agree that dunder methods should appear at the bottom of the auto-complete list.

The OP's issue—that learners are using dunder methods inappropriately—shouldn't be addressed by gimping auto-complete. 😢 It should be addressed by improving Mojo's educational materials!

@ematejska ematejska removed the mojo-tooling Tag for all issues related to repl, lldb, lsp, vscode extension. label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Initiative: LSP mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

6 participants