Skip to content

Added support for MyPy #1972

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

Merged
merged 21 commits into from
Jan 3, 2022
Merged

Added support for MyPy #1972

merged 21 commits into from
Jan 3, 2022

Conversation

GameDungeon
Copy link
Contributor

@GameDungeon GameDungeon commented Aug 29, 2021

Overview: What does this pull request change?

I added mypy support, including the pre-commit hook, and also fixed some issues mypy brought up.

Many things are ignored, it is a task for future pulls to fix the issues.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@GameDungeon
Copy link
Contributor Author

While we have been using mypy to fix issues in manim for a while, I think that it's important to be officially part of manim's developer tool kit.

Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no experience with MyPy at all, it would be great if someone else could look at the concrete changes here.

I don't particularly like the addition of 7 new dependencies.

config: Any
frame: Any

def tempconfig(temp: Union[ManimConfig, dict]) -> _GeneratorContextManager: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can these types not be added to the actual code file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The capitalized colors are generated in runtime so it does not work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not about color.pyi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh sorry. Mypy was interacting weirdly and this seemed to be the most direct solution.

@GameDungeon
Copy link
Contributor Author

The new dependencies are Dev Dependecys, and you can't get much more maintained than under the python github account + microsoft

@hydrobeam
Copy link
Member

What's the point of mypy? I'm not even sure why we need it.

@GameDungeon
Copy link
Contributor Author

Static Type checking. It finds bugs in our documentation & code. If we mark functions for the wrong types it can mislead people. There have already been several prs fixing mypy errors.

@christopher-besch
Copy link
Member

This looks like something we could really use.
Adding the type-hint dependencies shouldn't be an issue; they aren't that big and are required anyway if we want to make Manim type-safe. I don't think there is any way around MyPy once we move to the new dev-branch.

What I don't understand is why the .pyi files were changed.

@GameDungeon
Copy link
Contributor Author

This pull is old enough that if we plan to merge it, it might be better to delete the pyi files.

@christopher-besch
Copy link
Member

I gave it a run and this was the result:
image

Did I do something wrong?

@christopher-besch christopher-besch self-requested a review November 21, 2021 07:56
@GameDungeon
Copy link
Contributor Author

GameDungeon commented Nov 21, 2021

Try only running it on manim's folder. I did not do anything with the testing.

@GameDungeon GameDungeon requested a review from behackl November 21, 2021 16:17
@christopher-besch
Copy link
Member

Try only running it on manim's folder.

I still get this error:
image

@christopher-besch
Copy link
Member

We should also add this to the .pre-commit-config.yaml.

@GameDungeon
Copy link
Contributor Author

GameDungeon commented Dec 22, 2021

I've been away for a while, sorry for the really late response. I believe it's too early to add it to pre-commit. That one error was introduced since I made this.

@christopher-besch
Copy link
Member

Could you also merge any new changes to Manim and check if MyPy runs?

GameDungeon and others added 3 commits December 26, 2021 10:31
Co-authored-by: Christopher Besch <christopher.besch@gmx.de>
@GameDungeon
Copy link
Contributor Author

I think everything is up to data and functioning now :) I fixed the logger error as well.

@GameDungeon
Copy link
Contributor Author

I also managed to get the mypy pre-commit hook working :)

@GameDungeon GameDungeon changed the title Adding Manual MyPy Support Adding MyPy Support & Hook Dec 26, 2021
@christopher-besch
Copy link
Member

I ran it on my machine and everything seems to be working. With pre-commit it is also being run in CI.
I think we can merge this.

Thanks for the contribution!

@christopher-besch christopher-besch changed the title Adding MyPy Support & Hook Adding MyPy Support Dec 31, 2021
Copy link
Member

@Darylgolden Darylgolden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, thank you!

@Darylgolden Darylgolden changed the title Adding MyPy Support Added MyPy Support Jan 3, 2022
@Darylgolden Darylgolden added the maintenance refactoring, typos, removing clutter/dead code, and other code quality improvements label Jan 3, 2022
@Darylgolden Darylgolden merged commit c421773 into ManimCommunity:main Jan 3, 2022
@GameDungeon GameDungeon deleted the mypy branch January 5, 2022 03:57
@behackl behackl changed the title Added MyPy Support Added support for MyPy Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance refactoring, typos, removing clutter/dead code, and other code quality improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants