-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Type annotation work in manim/mobject/geometry/ #3961
Type annotation work in manim/mobject/geometry/ #3961
Conversation
The following four errors are removed with the commit. manim/mobject/geometry/labeled.py:63: error: Function is missing a type annotation for one or more arguments [no-untyped-def] manim/mobject/geometry/labeled.py:70: error: Incompatible default for argument "frame_fill_color" (default has type "None", argument has type "ManimColor | int | str | tuple[int, int, int] | tuple[float, float, float] | <6 more items>") [assignment] manim/mobject/geometry/labeled.py:82: error: Incompatible types in assignment (expression has type "MathTex | Text", variable has type "MathTex") [assignment] manim/mobject/geometry/labeled.py:150: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
The following errors are removed with the commit. manim/mobject/geometry/tips.py:115: error: Function is missing a type annotation for one or more arguments [no-untyped-def] manim/mobject/geometry/tips.py:208: error: Function is missing a type annotation [no-untyped-def] manim/mobject/geometry/tips.py:232: error: Function is missing a return type annotation [no-untyped-def] manim/mobject/geometry/tips.py:245: error: Function is missing a type annotation for one or more arguments [no-untyped-def] manim/mobject/geometry/tips.py:273: error: Function is missing a type annotation for one or more arguments [no-untyped-def] manim/mobject/geometry/tips.py:282: error: Function is missing a type annotation for one or more arguments [no-untyped-def] manim/mobject/geometry/tips.py:301: error: Function is missing a type annotation for one or more arguments [no-untyped-def] manim/mobject/geometry/tips.py:310: error: Function is missing a type annotation for one or more arguments [no-untyped-def] manim/mobject/geometry/tips.py:333: error: Function is missing a type annotation for one or more arguments [no-untyped-def] The following errors are still present: manim/mobject/geometry/tips.py:167: error: Unsupported left operand type for - ("tuple[float, float, float]") [operator] manim/mobject/geometry/tips.py:167: note: Both left and right operands are unions manim/mobject/geometry/tips.py:230: error: Argument 1 to "scale" of "Mobject" has incompatible type "floating[Any]"; expected "float" [arg-type]
TypeErrorCount: 1773
Hey thanks for helping out with the typing!
Most likely, you shouldn't be using the |
Thanks for the tip about My plan is to focus on getting rid of most of these errors:
Now the type of errors reported by mypy for the files in mobject/geometry looks like shown below.
|
A lot of those are quite difficult (mostly because Manim was not designed with typing in mind!) I would just For ones about returning If it's being annoying about numpy arrays being a If you need any more help or the PR is ready to review feel free to tag me :) P.S. this might be useful https://docs.manim.community/en/latest/contributing/docs/types.html |
The method is only used in one location where the return value is not stored.
Ok, status is that 21 errors are currently reported by mypy in the
|
…he constructor." This reverts commit 80ae857.
For the first error, I'm not quite sure why mypy complains - does it think that You can The third looks like a bug in Manim ( assert self.path_arc is not None before creating the |
As I read the code, the Arrow class is derived from the Line class.
Fine.
Perfect, a solution is then found! Thanks for the input. |
@JasonGrace2282 When I earlier activated mypy on the CI workflow link, it found a lot of errors. Therefore it was deactivated again. The Code scanning results / CodeQL fails with a warning and a failure. The docs/readthedocs.org:manimce build also fails. |
Looking at the CI/CodeQL comments, I think it's fine to ignore them. About the docs build, that was recently fixed - you might have to resolve conflicts and then merge main into this branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for tackling this issue. I remember trying to type this back when I was first starting with Manim, and it's nice to see it done much more thoroughly and correctly.
I did leave some comments/questions, so it would be nice to work towards getting those worked out so that everyone can enjoy the benefits of IDE completion :)
Thanks for helping make Manim better ✨
Co-authored-by: Aarush Deshpande <[email protected]>
Thanks for all the suggestions. I have added a comment to each of the suggestions. In most cases I have implemented the suggestion. In the cases where I haven't implemented the suggestion a detailed comment explains why. |
@JasonGrace2282 It seems like the CI flow does not activate the tests, they are listed as "Expected -- Waiting for status to be reported". |
…ype_annotation_work
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and enabled type-checking of manim.mobject.geometry.*
in CI. Thanks so much for taking on the challenge of finishing/fixing these typehints :)
Overview: What does this pull request change?
The pull request is meant as a first step towards getting the automatic type annotations (mypy) to work on the codebase.
Motivation and Explanation: Why and how do your changes improve the library?
I found this issue listed as as "good first issue"
#2121
This lead to this issue
#3375
Further Information and Comments
The main issue that I am struggling with at the moment, are type errors like the one listed below
The issue is that mypy do not think that two Point3D objects can be subtracted from each other.
This operation is performed in multiple locations of the codebase, e.g. line 180 in arc.py
angles = cartesian_to_spherical(handle - anchor)
Reviewer Checklist