-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Added type annotations to mobject/svg/brace.py #4309
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
base: main
Are you sure you want to change the base?
Conversation
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! I just reviewed and left some suggestions:
@@ -238,7 +240,7 @@ def __init__( | |||
font_size: float = DEFAULT_FONT_SIZE, |
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.
The label_constructor
above could be typed as type[SingleStringMathTex | Text]
to allow passing both TeX and Cairo-rendered texts. SingleStringMathTex
is the parent of MathTex
, which is the parent of Tex
, which is the parent of BulletedList
and Title
.
Plus, the brace_direction
could be typed as Point3DLike
(in the future, Vector3DLike
).
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.
Changing the type of label_constructor raises this error
manim/mobject/svg/brace.py:279: error: Argument 1 to "SingleStringMathTex" has incompatible type "*tuple[str, ...]"; expected "float" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "SingleStringMathTex" has incompatible type "*tuple[str, ...]"; expected "bool" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "SingleStringMathTex" has incompatible type "*tuple[str, ...]"; expected "float | None" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "SingleStringMathTex" has incompatible type "*tuple[str, ...]"; expected "TexTemplate | None" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "Text" has incompatible type "*tuple[str, ...]"; expected "float" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "Text" has incompatible type "*tuple[str, ...]"; expected "dict[str, str]" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "Text" has incompatible type "*tuple[str, ...]"; expected "dict[str, tuple[Any, ...]]" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "Text" has incompatible type "*tuple[str, ...]"; expected "tuple[Any, ...]" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "Text" has incompatible type "*tuple[str, ...]"; expected "int" [arg-type]
manim/mobject/svg/brace.py:279: error: Argument 1 to "Text" has incompatible type "*tuple[str, ...]"; expected "bool" [arg-type]
for more information, see https://pre-commit.ci
def change_label(self, *text, **kwargs): | ||
self.label = self.label_constructor(*text, **kwargs) | ||
|
||
def change_label(self, *text: str, **kwargs: Any) -> Self: |
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 have created this small example to demonstrate the use of the change_label
method, but apparently calling the method has no effect on the generated output.
from manim import *
class BraceExample(Scene):
def construct(self):
s1 = Square().move_to(2*LEFT)
self.add(s1)
br1 = BraceText(s1, "Label")
self.add(br1)
s2 = Square().move_to(2*RIGHT)
self.add(s2)
br2 = BraceText(s2, "Label")
# I would expect this line to change the label
# of the br2 brace to "new". But this is not seen
# in the output.
br2.change_label("new")
self.add(br2)
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.
There is a problem with the current implementaiton of change_label
-- essentially, the method needs to be changed such that it reads along the lines of
def change_label(self, ...):
self.remove(self.label)
...
self.label = ...
self.add(self.label)
return self
(also see #4339 ...)
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'd be fine with merging the type hint changes from here, but please either open another PR for fixing the change_label
method, or leave the example from your comment in an issue to document this problem.
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 have created an issue that describes the problem.
#4340
Overview: What does this pull request change?
Type annotations were added to the brace.py file.
Reviewer Checklist