Skip to content

Conversation

@multimeric
Copy link
Contributor

@multimeric multimeric commented Jul 31, 2025

Another, simpler attempt at #448.

The logic behind this is that omero.model imports classes from omero_model_XXX but type checkers can't understand this because it's done dynamically. If we put the imports into a if TYPE_CHECKING guard, it won't run at runtime but type checkers will at least understand the link.

This approach still lacks actual type annotations, but to solve this we could need to address #469 and/or zeroc-ice/ice#4264.

Mypy probably still won't like this, because there are a lot of other type issues including the fact it can't statically analyse the parent class relationships which requires zeroc-ice/ice#4265. Still, this should be an improvement because you can list and navigate to the class definitions in VS Code:
Screenshot 2025-07-31 at 4 39 15 PM

The pylance server also seems to understand which methods the class has:
Screenshot 2025-07-31 at 4 42 17 PM

But it doesn't understand instance methods because of zeroc-ice/ice#4265.
Screenshot 2025-07-31 at 4 42 37 PM

@multimeric
Copy link
Contributor Author

Actually you can fix the above error by adding a tiny Ice stub:

$ cat typings/Ice/Ice.pyi
from typing import Any

def openModule(module: str) -> Any: ...
Screenshot 2025-07-31 at 5 35 53 PM

In theory this should be fixed upstream in Ice, but we're using 3.6 so any upstream changes won't reach us anyway.

@pepone
Copy link

pepone commented Jul 31, 2025

Would you be able to upgrade to Ice 3.8, which targets Python 3.12 and above, once it is released?

@multimeric
Copy link
Contributor Author

That's an interesting question, and probably the best solution here. I'll open another issue.

@sbesson
Copy link
Member

sbesson commented Jul 31, 2025

@pepone from a maintenance perspective, we are aware that Ice will need to be upgraded at some stage. From previous experiences, we are arguably talking of the most challenging OMERO dependency. The complexity here is that the impact of the library upgrade goes way beyond the scope of OMERO.py as similar changes will need to be applied to OMERO server as well as every OMERO client. Practically, we are talking of a backwards-incompatible change affecting the whole OMERO ecosystem associated with a significant amount of scoping, work and coordination both on the development & testing as well as the deployment side. At present, there is no plan for such an effort by the OME & Glencoe Software teams.

Specifically for OMERO.py, the Python 3.12+ requirement for Ice 3.8 is another concern as it is more restrictive than the minimal requirement for this library which is currently Python 3.9+, probably moving to 3.10+ later in the year as Python 3.9 goes officially EOL.

@joshmoore
Copy link
Member

Since omero-py wouldn't be installed with Ice>3.6 for the moment, would it be safe to ship typings/Ice/Ice.pyi here?

@multimeric
Copy link
Contributor Author

No, that file couldn't be included in omero-py, I believe we can only include type stubs for our own package. The solution I suggest above is for the end user to create a typings stub folder in each project that uses omero-py.

Another option is to move all the type annotations into a separate stub-only package which I believe could include Ice stubs as well. This has the added benefit of allowing .pyi files for all the top-level OMERO models too, meaning that we get actual types and not just method autocompletion. The downside is that its no longer co-located or maintained together with omero-py.

@sbesson sbesson requested a review from joshmoore November 25, 2025 13:34
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.

4 participants