Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henrikmidtiby
Copy link
Contributor

Overview: What does this pull request change?

Type annotations were added to the brace.py file.

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

Copy link
Contributor

@chopan050 chopan050 left a 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:

Comment on lines +280 to +281
# TODO: This method is only called from the method change_brace_label, which is
# not called from any location in the current codebase.
Copy link
Contributor

Choose a reason for hiding this comment

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

Although it's not called anywhere, it seems like an useful method to be exposed to the end user. In that case, the real problem would be that it's not documented at all. This could be a good follow-up PR.

Suggested change
# TODO: This method is only called from the method change_brace_label, which is
# not called from any location in the current codebase.

self.label = self.label_constructor(*text, **kwargs)

self.brace.put_at_tip(self.label)
return self

def change_brace_label(self, obj, *text, **kwargs):
# TODO: This method is not called from anywhere in the codebase.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: seems useful, but it's not documented.

Suggested change
# TODO: This method is not called from anywhere in the codebase.

Comment on lines +270 to +272
# TODO: This method is only called from the method change_brace_label, which is
# not called from any location in the current codebase.
# TODO: The Mobject could be more specific.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. Btw, the suggestion is also removing the second TODO, but we can keep it if necessary. What do you exactly mean by that second TODO?

Suggested change
# TODO: This method is only called from the method change_brace_label, which is
# not called from any location in the current codebase.
# TODO: The Mobject could be more specific.

@@ -238,7 +240,7 @@ def __init__(
font_size: float = DEFAULT_FONT_SIZE,
Copy link
Contributor

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).

@@ -238,7 +240,7 @@ def __init__(
font_size: float = DEFAULT_FONT_SIZE,
buff: float = 0.2,
brace_config: dict | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
brace_config: dict | None = None,
brace_config: dict[str, Any] | None = None,

@@ -70,14 +72,14 @@ def construct(self):
def __init__(
self,
mobject: Mobject,
direction: Vector3D | None = DOWN,
direction: Vector3D = DOWN,
Copy link
Contributor

Choose a reason for hiding this comment

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

Might this be typed as Point3DLike in the meantime?

Suggested change
direction: Vector3D = DOWN,
direction: Point3DLike = DOWN,

Comment on lines 336 to 338
point_1: Point3DLike | None,
point_2: Point3DLike | None,
direction: Vector3D | None = ORIGIN,
Copy link
Contributor

Choose a reason for hiding this comment

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

If any of point_1 and point_2 is None, the code below raises an error. direction should also be different from None.

Suggested change
point_1: Point3DLike | None,
point_2: Point3DLike | None,
direction: Vector3D | None = ORIGIN,
point_1: Point3DLike,
point_2: Point3DLike,
direction: Point3DLike = ORIGIN,

Comment on lines +296 to +298
def __init__(
self, obj: Mobject, text: str, label_constructor: type[Tex] = Tex, **kwargs: Any
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before:

Suggested change
def __init__(
self, obj: Mobject, text: str, label_constructor: type[Tex] = Tex, **kwargs: Any
):
def __init__(
self,
obj: Mobject,
text: str,
label_constructor: type[SingleStringMathTex | Text] = Tex,
**kwargs: Any,
):

@@ -387,7 +403,7 @@ def __init__(
self,
arc: Arc | None = None,
direction: Sequence[float] = RIGHT,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
direction: Sequence[float] = RIGHT,
direction: Point3DLike = RIGHT,

@github-project-automation github-project-automation bot moved this from 🆕 New to 👀 In review in Dev Board Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

2 participants