omero-py
omero-py copied to clipboard
Add model stubs
Closes #448.
Thanks for opening this, @multimeric!
I'm failing to get the mypy errors to go away. Could you perhaps provide an example of what you're seeing before and after the change?
Can you attach some of these errors please? The PR won't solve all mypy errors but it should eliminate some and clarify others.
In my case, the stub module is not being found. I'm likely just doing something wrong.
In my case, the stub module is not being found. I'm likely just doing something wrong.
I've now added the py.typed file which should tell your IDE that there are type annotations available.
Other changes:
- Added annotations for
enums.pyi - Developed an automated approach that uses MonkeyType to run the unit tests and extract the runtime types, which I merged into the annotations. So now there are fewer
Incompleteannotations. Let me know if you think it makes sense to add the automated script to the repo so that devs can re-generate the annotations automatically. - Filtered out the
begin_,end_and other private classes. I don't think they're effectively public so it's cleaner to remove them from the stubs.
I played around with using a language model to annotate the missing ones and it would be possible in theory, but the downside is that it becomes no longer automated, and also LLMs really struggle with the 20K-line files that we're dealing with so I couldn't get one to actually process the whole file.
Hmm part of the problem is these top level files that live directly in site-packages, like omero_model_CodomainMapContextI.py, which are used directly in the unit tests instead of omero.model. They make it incredibly difficult to install .pyi files and even if you do it, it doesn't seem like mypy detects them. Is there any plan to move them into a module?
There's no current plan, no, but happy to either help someone do it or review work to attempt it.