Fixed structure of typing-related files #270
Open
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.
Hi! I'm using PyGLM in a library, and recently I tried to get my library to pass pyright's strict type checking. In doing so, I noticed a few issues with the provided type stubs.
Some of the issues are caused by the new (2.8.0) packaging structure of pyglm, and some are caused by omissions and mistakes in the type stub files themselves. I was a little confused at first whether I sould submit fixes to this repository or to the pyglm-typing repository, since the type stubs are now also included in the main pyglm repository directly. I eventually concluded that it would probably be best to submit fixes to the type stub files themselves to the pyglm-typing repo, and submit fixes to the packaging structure here. See my PR in pyglm-typing for my reasoning (and for the type stub file fixes). Please let me know if I should have done it differently, though!
Explanation of the changes:
First of all, the main type stub file was duplicated in
pyglm/__init__.pyi
andpyglm-stubs/glm/__init__.pyi
. I'm pretty sure thatpyglm/__init__.pyi
wasn't actually doing anything, since the glm objects are imported frompyglm.glm
, notpyglm
. I think this could be solved by renamingpyglm/__init__.pyi
topyglm/glm.pyi
orpyglm/glm/__init__.pyi
, but I instead opted to remove it in favor of the file inpyglm-stubs
, sincepyglm-stubs
also contains thepyglm-typing
license.In
pyglm-stubs
, the filepyglm-stubs/__init__.pyi
was missing. This caused an error on the importfrom pyglm import glm
. I added this file.The main stub file in
pyglm-stubs
used to be atpyglm-stubs/glm/__init__.pyi
. This structure is more complex than needed and doesn't actually match the way that the pyglm package is structured. I changed the structure to the simplerpyglm-stubs/glm.pyi
.pyglm-stubs/glm/__init__.pyi
(nowpyglm-stubs/glm.pyi
) contained the importfrom PyGLM import glm_typing
. This import didn't work for various reasons. The pyglm package ispyglm
, notPyGLM
, and even after changing this, the import could not be resolved. I wasn't sure how to fix this, since the whole construction seemed pretty magical: the stubs apparently want to importglm_typing
, which refers to glm types, and thus relies on the glm stubs - a circle! And indeed, the type stubs that relied onglm_typing
didn't actually work. I believe that the proper way to handle this would be to include the contents ofglm_typing
inpyglm-stubs/glm.pyi
, but that would require changing all references to glm types from e.g.glm.vec3
tovec3
, which seemed cumbersome. Instead, I copiedglm_typing.py
topyglm-stubs/glm_typing.py
, and changed the import inpyglm-stubs/glm.pyi
tofrom . import glm
. I'm not entirely sure why, but this does seem to work.I removed
glm/py.typed
. The files there don't provide types via type annotations, so I believepy.typed
is not appropriate. There were actually no type hints for imports fromglm
at all, only forpyglm.glm
, but that didn't seem like much of a problem sinceglm
is deprecated. Note that git seems to think that I renamedglm/py.typed
topyglm-stubs/__init__.pyi
, but really it's just a removal of an empty file and an addition of an empty file... Well, thanks for reading that wall of text. :)