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

Add add_overloaded_method_to_class helper to plugins/common.py #16038

Merged
merged 12 commits into from
Sep 10, 2023

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 4, 2023

There are several changes:

  1. add_overloaded_method_to_class itself. It is very useful for plugin authors, because right now it is quite easy to add a regular method, but it is very hard to add a method with @overloads. I don't think that user must face all the chalenges that I've covered in this method. Moreover, it is quite easy even for experienced developers to forget some flags / props / etc (I am pretty sure that I might forgot something in the implementation)
  2. add_overloaded_method_to_class and add_method_to_class now return added nodes, it is also helpful if you want to do something with this node in your plugin after it is created
  3. I've refactored how add_method_to_class works and reused its parts in the new method as well
  4. tvar_def in add_method_to_class can now accept a list of type vars, not just one

Notice that add_method_to_class is unchanged from the user's POV, it should continue to work as before.

Tests are also updated to check that our overloads are correct.

Things to do later (in the next PRs / releases):

  1. We can possibly add is_final param to methods as well
  2. We can also support @property in a separate method at some point

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@sobolevn sobolevn closed this Sep 4, 2023
@sobolevn sobolevn reopened this Sep 4, 2023
@sobolevn
Copy link
Member Author

sobolevn commented Sep 4, 2023

GitHub is down 😒

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@sobolevn sobolevn merged commit 9a35360 into master Sep 10, 2023
17 checks passed
@sobolevn sobolevn deleted the add-overloaded-method branch September 10, 2023 18:11
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

Successfully merging this pull request may close these issues.

2 participants