Skip to content

Commit c421773

Browse files
GameDungeonpre-commit-ci[bot]christopher-besch
authored
Added MyPy Support (#1972)
* MyPy Support * MyPy Hook * Removing MyPy Hook * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Delete __init__.pyi * Delete color.pyi * Update .mypy.ini Co-authored-by: Christopher Besch <christopher.besch@gmx.de> * changes * quick fix * MyPy Hook * MyPy Hook Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christopher Besch <christopher.besch@gmx.de>
1 parent 7399c24 commit c421773

18 files changed

+312
-16
lines changed

.mypy.ini

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[mypy]
2+
show_error_codes = True
3+
4+
# ignore most files; should be checked once proper types have been implemented
5+
[mypy-manim.__main__]
6+
ignore_errors = True
7+
8+
[mypy-manim.camera.*]
9+
ignore_errors = True
10+
11+
[mypy-manim.scene.*]
12+
ignore_errors = True
13+
14+
[mypy-manim.cli.cfg.*]
15+
ignore_errors = True
16+
17+
[mypy-manim.mobject.*]
18+
ignore_errors = True
19+
20+
[mypy-manim._config.*]
21+
ignore_errors = True
22+
23+
[mypy-manim.utils.*]
24+
ignore_errors = True
25+
26+
[mypy-manim.animation.*]
27+
ignore_errors = True
28+
29+
# ---------------- We can't properly type this ------------------------
30+
31+
[mypy-manim.grpc.*]
32+
ignore_errors = True
33+
34+
# ---------------- Stubless imported Modules --------------------------
35+
36+
# We should be able to create stubs for this or type hint it
37+
[mypy-manimpango]
38+
ignore_missing_imports = True
39+
40+
# Has stubs in 3.8
41+
[mypy-numpy]
42+
ignore_missing_imports = True
43+
44+
# Has stubs in 3.8
45+
[mypy-pydub]
46+
ignore_missing_imports = True
47+
48+
[mypy-matplotlib]
49+
ignore_missing_imports = True
50+
51+
[mypy-scipy.*]
52+
ignore_missing_imports = True
53+
54+
[mypy-networkx]
55+
ignore_missing_imports = True
56+
57+
[mypy-git]
58+
ignore_missing_imports = True
59+
60+
[mypy-moderngl.*]
61+
ignore_missing_imports = True
62+
63+
[mypy-moderngl_window.*]
64+
ignore_missing_imports = True
65+
66+
[mypy-colour]
67+
ignore_missing_imports = True
68+
69+
[mypy-dearpygui.*]
70+
ignore_missing_imports = True
71+
72+
[mypy-screeninfo]
73+
ignore_missing_imports = True
74+
75+
[mypy-IPython.*]
76+
ignore_missing_imports = True
77+
78+
[mypy-watchdog.*]
79+
ignore_missing_imports = True
80+
81+
[mypy-tqdm]
82+
ignore_missing_imports = True
83+
84+
[mypy-mapbox_earcut]
85+
ignore_missing_imports = True
86+
87+
[mypy-click_default_group]
88+
ignore_missing_imports = True

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ repos:
5555
additional_dependencies: [flake8-builtins==1.5.3, flake8-bugbear==21.4.3,
5656
flake8-docstrings==1.6.0, flake8-rst-docstrings==0.2.3,
5757
flake8-pytest-style==1.5.0, flake8-simplify==0.14.1, flake8-comprehensions>=3.6.1]
58+
- repo: https://github.com/pre-commit/mirrors-mypy
59+
rev: 'v0.930'
60+
hooks:
61+
- id: mypy
62+
additional_dependencies: [types-decorator, types-docutils, types-requests, types-setuptools]
63+
5864
- repo: https://github.com/codespell-project/codespell
5965
rev: v2.1.0
6066
hooks:

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# This pattern also affects html_static_path and html_extra_path.
7070
html_extra_path = ["robots.txt"]
7171

72-
exclude_patterns = []
72+
exclude_patterns: list = []
7373

7474
# -- Options for internationalization ----------------------------------------
7575
# Set the destination directory of the localized po files

example_scenes/opengl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import manim.utils.opengl as opengl
55
from manim import *
6-
from manim.opengl import *
6+
from manim.opengl import * # type: ignore
77

88
# Copied from https://3b1b.github.io/manim/getting_started/example_scenes.html#surfaceexample.
99
# Lines that do not yet work with the Community Version are commented.

manim/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pkg_resources
55

6-
__version__ = pkg_resources.get_distribution(__name__).version
6+
__version__: str = pkg_resources.get_distribution(__name__).version
77

88

99
import sys

manim/_config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
]
1818

1919
parser = make_config_parser()
20+
logger: logging.Logger
2021

2122
# The logger can be accessed from anywhere as manim.logger, or as
2223
# logging.getLogger("manim"). The console must be accessed as manim.console.

manim/cli/render/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@click.argument("scene_names", required=False, nargs=-1)
3131
@global_options
3232
@output_options
33-
@render_options
33+
@render_options # type: ignore
3434
@ease_of_access_options
3535
def render(
3636
**args,

manim/cli/render/render_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def validate_resolution(ctx, param, value):
6262
"--quality",
6363
default=None,
6464
type=click.Choice(
65-
list(reversed([q["flag"] for q in QUALITIES.values() if q["flag"]])),
65+
list(reversed([q["flag"] for q in QUALITIES.values() if q["flag"]])), # type: ignore
6666
case_sensitive=False,
6767
),
6868
help="Render quality at the follow resolution framerates, respectively: "

manim/plugins/import_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# essentially this would be similar to `from plugin import *``
2323
# if not just import the module with the plugin name
2424
if hasattr(loaded_plugin, "__all__"):
25-
for thing in loaded_plugin.__all__:
25+
for thing in loaded_plugin.__all__: # type: ignore
2626
exec(f"{thing}=loaded_plugin.{thing}")
2727
__all__.append(thing)
2828
else:

manim/renderer/cairo_renderer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def save_static_frame_data(
201201
self,
202202
scene,
203203
static_mobjects: typing.Iterable[Mobject],
204-
) -> typing.Iterable[Mobject]:
204+
) -> typing.Optional[typing.Iterable[Mobject]]:
205205
"""Compute and save the static frame, that will be reused at each frame to avoid to unecesseraly computer
206206
static mobjects.
207207
@@ -219,7 +219,7 @@ def save_static_frame_data(
219219
"""
220220
if not static_mobjects:
221221
self.static_image = None
222-
return
222+
return None
223223
self.update_frame(scene, mobjects=static_mobjects)
224224
self.static_image = self.get_frame()
225225
return self.static_image

manim/renderer/shader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from ..utils.simple_functions import get_parameters
1212

1313
SHADER_FOLDER = Path(__file__).parent / "shaders"
14-
shader_program_cache = {}
15-
file_path_to_code_map = {}
14+
shader_program_cache: dict = {}
15+
file_path_to_code_map: dict = {}
1616

1717
__all__ = [
1818
"Object3D",

manim/renderer/shader_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def combine_with(self, *shader_wrappers):
152152

153153

154154
# For caching
155-
filename_to_code_map = {}
155+
filename_to_code_map: dict = {}
156156

157157

158158
def get_shader_code_from_file(filename):

manim/utils/docbuild/manim_directive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def construct(self):
8585

8686
import jinja2
8787
from docutils import nodes
88-
from docutils.parsers.rst import Directive, directives
88+
from docutils.parsers.rst import Directive, directives # type: ignore
8989
from docutils.statemachine import StringList
9090

9191
from manim import QUALITIES

0 commit comments

Comments
 (0)