omero-py icon indicating copy to clipboard operation
omero-py copied to clipboard

Add model stubs

Open multimeric opened this issue 8 months ago • 6 comments

Closes #448.

multimeric avatar Mar 12 '25 04:03 multimeric

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?

joshmoore avatar May 08 '25 10:05 joshmoore

Can you attach some of these errors please? The PR won't solve all mypy errors but it should eliminate some and clarify others.

multimeric avatar May 26 '25 07:05 multimeric

In my case, the stub module is not being found. I'm likely just doing something wrong.

joshmoore avatar May 26 '25 08:05 joshmoore

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 Incomplete annotations. 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.

multimeric avatar Jul 30 '25 07:07 multimeric

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?

multimeric avatar Jul 30 '25 08:07 multimeric

There's no current plan, no, but happy to either help someone do it or review work to attempt it.

joshmoore avatar Jul 30 '25 16:07 joshmoore