add type annotations and docstrings for opengl_renderer.py #4537
+725
−139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
Motivation and Explanation: Why and how do your changes improve the library?
For #3375
Links to added or changed documentation pages
Further Information and Comments
The typing revealed a bug in the
get_texture_idmethod: it is passed a path (string), but throughout the function it is treated as if it were a PIL Image. No test triggers this call, and I did not find anything that could trigger it. To trigger it, there must be a mobject that has a shader inmobject.get_shader_wrapper_list()with a non-emptyshader.texture.texture_paths. To fix this, thecreate_texturemethod open the path into a PIL Image.Also, there are some uses of
typing.cast. This is because of the implicit contracts "using OpenGLRenderer => the camera is an OpenGLCamera" and "using OpenGLRenderer => all mobjects are OpenGLMobject or OpenGLVMobject”. I think the proper way to deal with this would be to introduce generics in the Scene class, such asScene[CameraType, MobjectType], and define protocol classes to bound these types. For example, for the camera:but the cast seems quite reasonable compared to this complexity.
Reviewer Checklist