-
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
Typing mobject text #4092
base: main
Are you sure you want to change the base?
Typing mobject text #4092
Conversation
manim/mobject/text/code_mobject.py
Outdated
# TODO | ||
# Fix the mypy error from the next line of code. | ||
# "Argument 1 to "append" of "list" has incompatible type "list[str]"; expected "str" [arg-type]" | ||
self.code_json[code_json_line_index].append([text, color]) # type: ignore[arg-type] |
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 need input to solve the mypy issue mentioned here.
# TODO: I am not sure about the type of mob_class. | ||
# I think it should be SingleStringMathTex, as that class has the _fontsize property. | ||
# But this seems to conflict with the default case, where it is set to VMobject. | ||
string_to_mob_map[string] = mob_class(string, **kwargs) # type: ignore[assignment] |
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 need input to solve the mypy issue mentioned here.
@@ -38,7 +41,7 @@ | |||
from manim.utils.tex import TexTemplate | |||
from manim.utils.tex_file_writing import tex_to_svg_file | |||
|
|||
tex_string_to_mob_map = {} | |||
tex_string_to_mob_map: dict[str, VMobject] = {} |
Check notice
Code scanning / CodeQL
Unused global variable Note
# Give meaning full names to tex_strings_2 and tex_strings_3 | ||
tex_strings_2 = [re.split("{{(.*?)}}", str(t)) for t in tex_strings] | ||
tex_strings_3 = sum(tex_strings_2, []) | ||
if len(tex_strings_3) > pre_split_length: |
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 used separate names for tex_strings, tex_strings_2 and tex_strings_3 as their types differ. Changing type of a variable like triggers a mypy error.
part = self.get_part_by_tex(tex, **kwargs) | ||
return self.index_of_part(part) | ||
return self.index_of_part(part) # type: ignore[arg-type] |
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.
Is it possible to get rid of this type ignore?
self.buff = buff | ||
self.dot_scale_factor = dot_scale_factor | ||
self.tex_environment = tex_environment | ||
# TODO: See comment 10 lines above this |
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.
Would it be ok to set the default tex_environment to "center"?
code.code = mobject_without_dots | ||
# TODO: | ||
# error: "SVGMobject" has no attribute "code" [attr-defined] | ||
code.code = mobject_without_dots # type: ignore[attr-defined] |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
mobject = mobject.code | ||
# TODO: | ||
# error: Incompatible types in assignment (expression has type "MethodType", variable has type "SVGMobject") [assignment] | ||
mobject = mobject.code # type: ignore[assignment] |
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.
Any ideas of how to handle this typing issue?
code.code = mobject_without_dots | ||
# TODO: | ||
# error: "SVGMobject" has no attribute "code" [attr-defined] | ||
code.code = mobject_without_dots # type: ignore[attr-defined] |
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.
Any ideas of how to handle this typing issue?
file_name = self._text2svg(color.to_hex()) | ||
parsed_color: ManimColor = ManimColor(color) if color else VMobject().color | ||
# TODO: Should _text2svg receive a str or a ManimColor? | ||
file_name = self._text2svg(parsed_color.to_hex()) |
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.
Any ideas of how to handle this typing issue?
args["color"] = colors[i].to_hex() | ||
# TODO: | ||
# error: Item "float" of "ManimColor | float" has no attribute "to_hex" [union-attr] | ||
args["color"] = colors[i].to_hex() # type: ignore[union-attr] |
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.
Any ideas of how to handle this typing issue?
gradient = [ManimColor(color)] | ||
# TODO: | ||
# error: Incompatible types in assignment (expression has type "list[ManimColor]", variable has type "tuple[Any, ...]") [assignment] | ||
gradient = [ManimColor(color)] # type: ignore[assignment] |
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.
Any ideas of how to handle this typing issue?
color_gradient(gradient, len(word)) | ||
# TODO: | ||
# error: Incompatible types in assignment (expression has type "list[ManimColor] | ManimColor | tuple[Any, ...]", variable has type "list[ManimColor] | ManimColor") [assignment] | ||
color_gradient(gradient, len(word)) # type: ignore[assignment] |
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.
Any ideas of how to handle this typing issue?
args["color"] = colors[i - start].to_hex() | ||
# TODO: | ||
# error: Item "float" of "ManimColor | float" has no attribute "to_hex" [union-attr] | ||
args["color"] = colors[i - start].to_hex() # type: ignore[union-attr] |
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.
Any ideas of how to handle this typing issue?
settings = self._get_settings_from_t2xs(t2xs, default_args) # type: ignore[arg-type] | ||
# TODO: | ||
# error: Argument 1 to "_get_settings_from_gradient" of "Text" has incompatible type "dict[str, Any | ManimColor | int | str | tuple[int, int, int] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float]]"; expected "dict[str, Iterable[str]]" [arg-type] | ||
settings.extend(self._get_settings_from_gradient(default_args)) # type: ignore[arg-type] |
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.
Any ideas of how to handle this typing issue?
new_setting = self._merge_settings(setting, next_setting, default_args) | ||
# TODO: | ||
# error: Argument 3 to "_merge_settings" of "Text" has incompatible type "dict[str, Any | ManimColor | int | str | tuple[int, int, int] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float]]"; expected "dict[str, Iterable[str]]" [arg-type] | ||
new_setting = self._merge_settings(setting, next_setting, default_args) # type: ignore[arg-type] |
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.
Any ideas of how to handle this typing issue?
I would like to handle this PR eventually. In the meantime, @henrikmidtiby, PR #4115 completely rewrote the |
updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.1 → v0.9.2](astral-sh/ruff-pre-commit@v0.9.1...v0.9.2)
Error count: 156 # Conflicts: # mypy.ini
# Conflicts: # manim/mobject/text/code_mobject.py
# Conflicts: # manim/mobject/text/code_mobject.py
94382c5
to
ee181ac
Compare
|
Overview: What does this pull request change?
This pull request will add types to mobject/text/*.py
Motivation and Explanation: Why and how do your changes improve the library?
Links to added or changed documentation pages
Further Information and Comments
I indent to use this PR to share progress and get input on things that show up.
Reviewer Checklist