-
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
Add type annotations to manim.utils.* #3999
Changes from 1 commit
45d84fd
c2a715a
40250de
910aa3f
8bf07ca
5d2ce00
ec07a4f
bb3ec8a
d6210c3
21599b1
4997a37
3be6129
3cabd9e
29792df
9f0be52
111775b
459092e
be12a0f
713a03e
0970168
37d9071
c1a154a
15e10b2
1569831
714b49a
1b54065
7bf0312
8e15d0c
36906b8
0bfe02f
7b8a529
67acc91
2a29354
a50dd1a
e055ba1
d5686d1
b6b1ff0
f3ed2b1
3a4bd5b
98ff7a8
44a8645
e1db9ea
de80832
0736393
711b2d8
3f0d9ac
35e6597
8cce30f
3bb4f6b
0436034
3c5183c
6931d36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,18 @@ | |
import types | ||
import warnings | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from .. import config, console, constants, logger | ||
from ..scene.scene_file_writer import SceneFileWriter | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
__all__ = ["scene_classes_from_file"] | ||
|
||
|
||
def get_module(file_name: Path): | ||
def get_module(file_name: Path) -> types.ModuleType: | ||
if str(file_name) == "-": | ||
module = types.ModuleType("input_scenes") | ||
logger.info( | ||
|
@@ -47,19 +51,22 @@ def get_module(file_name: Path): | |
) | ||
|
||
spec = importlib.util.spec_from_file_location(module_name, file_name) | ||
module = importlib.util.module_from_spec(spec) | ||
sys.modules[module_name] = module | ||
sys.path.insert(0, str(file_name.parent.absolute())) | ||
spec.loader.exec_module(module) | ||
return module | ||
if isinstance(spec, importlib.machinery.ModuleSpec): | ||
module = importlib.util.module_from_spec(spec) | ||
sys.modules[module_name] = module | ||
sys.path.insert(0, str(file_name.parent.absolute())) | ||
assert spec.loader | ||
spec.loader.exec_module(module) | ||
return module | ||
raise FileNotFoundError(f"{file_name} not found") | ||
else: | ||
raise FileNotFoundError(f"{file_name} not found") | ||
|
||
|
||
def get_scene_classes_from_module(module): | ||
def get_scene_classes_from_module(module: types.ModuleType) -> list[Any]: | ||
from ..scene.scene import Scene | ||
|
||
def is_child_scene(obj, module): | ||
def is_child_scene(obj: Any, module: types.ModuleType) -> bool: | ||
return ( | ||
inspect.isclass(obj) | ||
and issubclass(obj, Scene) | ||
|
@@ -73,7 +80,7 @@ def is_child_scene(obj, module): | |
] | ||
|
||
|
||
def get_scenes_to_render(scene_classes): | ||
def get_scenes_to_render(scene_classes: list[Any]) -> list[Any]: | ||
henrikmidtiby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not scene_classes: | ||
logger.error(constants.NO_SCENE_MESSAGE) | ||
return [] | ||
|
@@ -97,7 +104,7 @@ def get_scenes_to_render(scene_classes): | |
return prompt_user_for_choice(scene_classes) | ||
|
||
|
||
def prompt_user_for_choice(scene_classes): | ||
def prompt_user_for_choice(scene_classes: list[Any]) -> list[Any]: | ||
num_to_class = {} | ||
henrikmidtiby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SceneFileWriter.force_output_as_scene_name = True | ||
for count, scene_class in enumerate(scene_classes, 1): | ||
|
@@ -125,8 +132,8 @@ def prompt_user_for_choice(scene_classes): | |
|
||
|
||
def scene_classes_from_file( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one could be overloaded like this: @overload
def scene_classes_from_file(
file_path: Path, require_single_scene: bool, full_list: Literal[True]
) -> list[type[Scene]]: ...
@overload
def scene_classes_from_file(
file_path: Path, require_single_scene: Literal[True], full_list: Literal[False] = False
) -> type[Scene]: ...
@overload
def scene_classes_from_file(
file_path: Path, require_single_scene: Literal[False] = False, full_list: Literal[False] = False
) -> list[type[Scene]]: ...
def scene_classes_from_file(
file_path: Path, require_single_scene: bool = False, full_list: bool = False
) -> type[Scene] | list[type[Scene]]:
# the rest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I try the changes that you suggest in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tried myself, everything was OK. |
||
file_path: Path, require_single_scene=False, full_list=False | ||
): | ||
file_path: Path, require_single_scene: bool = False, full_list: bool = False | ||
) -> list[Any] | Any: | ||
module = get_module(file_path) | ||
all_scene_classes = get_scene_classes_from_module(module) | ||
if full_list: | ||
|
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note