Skip to content

Add model stubs #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add model stubs #450

wants to merge 6 commits into from

Conversation

multimeric
Copy link
Contributor

Closes #448.

@joshmoore
Copy link
Member

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?

@multimeric
Copy link
Contributor Author

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

@joshmoore
Copy link
Member

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

@multimeric
Copy link
Contributor Author

multimeric commented Jul 30, 2025

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
Copy link
Contributor Author

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?

@joshmoore
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type annotations for omero.model
2 participants