Skip to content

Commit

Permalink
Add types to please mypy (#201)
Browse files Browse the repository at this point in the history
* typing: Replace deprecated aliases by buildin types

* typing: Add types to atlas/*, capture/*, conf/*

* typing: Add types to context/*

* typing: Add types to finders/* and geometry/*

* typing: Add types to meta/*, opengl/*, resources/*

* typing: add types to scene/*, text/*, utils/*

* typing: Add types to __init__, screenshot, timers/*

* tests: New test case to timers

* typing: Add types to loaders/*

* typing: Fix other mypy errors/warnings/notes

* Format: use isort

* typing: Add types to loaders/scene/gltf2.py

* Oversight on my part when pygame is not installed
  • Loading branch information
henri-gasc authored Nov 28, 2024
1 parent 9751fec commit cd2ae53
Show file tree
Hide file tree
Showing 142 changed files with 1,702 additions and 1,364 deletions.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
#
# import os
import sys

from typing import Any
# sys.path.insert(0, os.path.abspath('.'))
from unittest.mock import MagicMock


# Mock modules
class Mock(MagicMock):
@classmethod
def __getattr__(cls, name):
def __getattr__(cls: Any, name: Any) -> MagicMock:
return MagicMock()


Expand Down Expand Up @@ -141,7 +141,7 @@ def __getattr__(cls, name):

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
latex_elements: dict[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
Expand Down
6 changes: 4 additions & 2 deletions examples/advanced/animated_sprites.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import moderngl
from pathlib import Path

import glm
import moderngl

import moderngl_window as mglw
from moderngl_window import geometry
import glm

# from moderngl_window.conf import settings
# settings.SCREENSHOT_PATH = 'screenshots'
Expand Down
4 changes: 3 additions & 1 deletion examples/advanced/compute_render_to_texture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import moderngl as mgl
from pathlib import Path

import moderngl as mgl

import moderngl_window as mglw
from moderngl_window import geometry

Expand Down
3 changes: 2 additions & 1 deletion examples/advanced/fragment_picking.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import struct
from pathlib import Path

import moderngl
import glm
import moderngl

import moderngl_window
from moderngl_window import geometry
from moderngl_window.opengl.projection import Projection3D
Expand Down
1 change: 1 addition & 0 deletions examples/advanced/navier_stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import random
from pathlib import Path

import glm

import moderngl_window
Expand Down
6 changes: 4 additions & 2 deletions examples/advanced/pygame2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import math
from pathlib import Path
import pygame

import glm
import moderngl
import pygame

import moderngl_window
from moderngl_window import geometry
import glm

# from moderngl_window.conf import settings
# settings.SCREENSHOT_PATH = 'capture'
Expand Down
4 changes: 3 additions & 1 deletion examples/advanced/pygame2_background_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"""
import math
from pathlib import Path
import pygame

import moderngl
import pygame

import moderngl_window
from moderngl_window import geometry

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/pygame2_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import math
from array import array

import moderngl
import pygame

import moderngl
import moderngl_window


Expand Down
1 change: 1 addition & 0 deletions examples/advanced/shader_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
and render each quadrant of the screen with different blend types
"""
from pathlib import Path

import moderngl_window as mglw
from moderngl_window import geometry

Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/shadow_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import math
from pathlib import Path
import glm

import glm
import moderngl
from base import CameraWindow

import moderngl_window
from moderngl_window import geometry

from base import CameraWindow


class ShadowMapping(CameraWindow):
title = "Shadow Mapping"
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/shadow_mapping_56.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import math
from pathlib import Path
import glm

import glm
import moderngl
from base import CameraWindow

import moderngl_window
from moderngl_window import geometry

from base import CameraWindow


class ShadowMapping(CameraWindow):
title = "Shadow Mapping"
Expand Down
9 changes: 5 additions & 4 deletions examples/advanced/tetrahedral_mesh.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pathlib import Path
import numpy as np
import glm

import glm
import moderngl
from moderngl_window.opengl.vao import VAO
from moderngl_window import geometry
import numpy as np
from base import CameraWindow

from moderngl_window import geometry
from moderngl_window.opengl.vao import VAO


class VolumetricTetrahedralMesh(CameraWindow):
"""Volumetric Tetrahedral Mesh.
Expand Down
10 changes: 5 additions & 5 deletions examples/advanced/voxel_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* We can reduce a voxel volume dramatically by just inspecting neighbors
"""

from pathlib import Path
from typing import Tuple
from array import array
from pathlib import Path

import glm
import moderngl
from moderngl_window import geometry
from base import CameraWindow
import glm

from moderngl_window import geometry


class CubeVoxel(CameraWindow):
Expand Down Expand Up @@ -95,7 +95,7 @@ class Voxel:
We are sticking to simple transforms at textures.
"""

def __init__(self, *, ctx: moderngl.Context, size: Tuple[int, int, int]):
def __init__(self, *, ctx: moderngl.Context, size: tuple[int, int, int]):
self.ctx = ctx
self._size = size

Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/water.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"""
import random
from pathlib import Path
import numpy as np

import moderngl
import numpy as np

import moderngl_window
from moderngl_window import geometry
from moderngl_window import screenshot
from moderngl_window import geometry, screenshot


class Water(moderngl_window.WindowConfig):
Expand Down
5 changes: 3 additions & 2 deletions examples/cube_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pathlib import Path
import glm

import glm
import moderngl
import moderngl_window
from base import CameraWindow

import moderngl_window


class CubeModel(CameraWindow):
aspect_ratio = 16 / 9
Expand Down
4 changes: 2 additions & 2 deletions examples/cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from pathlib import Path

import glm
import moderngl
import moderngl_window

import glm
import moderngl_window


class Cubes(moderngl_window.WindowConfig):
Expand Down
1 change: 1 addition & 0 deletions examples/custom_config_class.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import random

import moderngl_window
from moderngl_window.conf import settings
from moderngl_window.timers.clock import Timer
Expand Down
1 change: 1 addition & 0 deletions examples/custom_config_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import math
import random

import moderngl_window
from moderngl_window.conf import settings
from moderngl_window.timers.clock import Timer
Expand Down
6 changes: 3 additions & 3 deletions examples/drag_drop_file_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Currently only working with the Pyglet backend.
"""
from pathlib import Path
import os
from pathlib import Path

import glm
import moderngl
import moderngl_window

import glm
import moderngl_window


class Cubes(moderngl_window.WindowConfig):
Expand Down
3 changes: 1 addition & 2 deletions examples/geometry_bbox.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import glm
from base import CameraWindow

import moderngl_window
from moderngl_window import geometry

from base import CameraWindow


class GeometryBbox(CameraWindow):
title = "BBox Geometry"
Expand Down
6 changes: 3 additions & 3 deletions examples/geometry_cube.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pathlib import Path
import glm

import glm
import moderngl
from base import CameraWindow

import moderngl_window
from moderngl_window import geometry

from base import CameraWindow


class CubeSimple(CameraWindow):
title = "Plain Cube"
Expand Down
5 changes: 3 additions & 2 deletions examples/geometry_cube_instanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

from pathlib import Path

import numpy
import glm
import moderngl
import numpy
from base import CameraWindow

import moderngl_window
from moderngl_window import geometry
from base import CameraWindow


class CubeSimpleInstanced(CameraWindow):
Expand Down
5 changes: 3 additions & 2 deletions examples/geometry_lines.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pathlib import Path

import glm
import moderngl
import numpy
from base import CameraWindow

import moderngl
import moderngl_window
from base import CameraWindow


class LinesDemo(CameraWindow):
Expand Down
3 changes: 1 addition & 2 deletions examples/geometry_quad_fs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pathlib import Path

import moderngl_window
from moderngl_window import geometry
from moderngl_window import resources
from moderngl_window import geometry, resources

resources.register_dir((Path(__file__).parent / 'resources').resolve())

Expand Down
3 changes: 1 addition & 2 deletions examples/geometry_quad_fs_mouse_scroll.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pathlib import Path

import moderngl_window
from moderngl_window import geometry
from moderngl_window import resources
from moderngl_window import geometry, resources

resources.register_dir((Path(__file__).parent / "resources").resolve())

Expand Down
5 changes: 3 additions & 2 deletions examples/gltf_scenes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pathlib import Path
import glm

import glm
import moderngl
from base import CameraWindow

import moderngl_window as mglw
from moderngl_window.scene.camera import KeyboardCamera
from base import CameraWindow


class CubeModel(CameraWindow):
Expand Down
3 changes: 2 additions & 1 deletion examples/headless.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import moderngl
import numpy as np
from PIL import Image
import moderngl

import moderngl_window


Expand Down
6 changes: 4 additions & 2 deletions examples/integration_imgui.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path

import glm
import moderngl
# import imgui
from imgui_bundle import imgui
import moderngl
import glm

import moderngl_window as mglw
from moderngl_window import geometry
from moderngl_window.integrations.imgui_bundle import ModernglWindowRenderer
Expand Down
5 changes: 3 additions & 2 deletions examples/integration_imgui_image.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pathlib import Path

import glm
import moderngl
# import imgui
from imgui_bundle import imgui
import moderngl
import glm

import moderngl_window as mglw
from moderngl_window import geometry
from moderngl_window.integrations.imgui_bundle import ModernglWindowRenderer
Expand Down
Loading

0 comments on commit cd2ae53

Please sign in to comment.