Skip to content

Conversation

@dstansby
Copy link
Collaborator

Currently the from_zarr() methods are not typed as returning sub-classes correctly. As a concrete example, this means that in this line:

https://github.com/BioImageTools/ome-zarr-models-py/blob/4a6851ed1487a90274058dc92ebc3a16539557ed/tests/v04/test_hcs.py#L12

the hcs variable does not have the type HCS, but instead a wider GroupSpec type.

This PR should fix that so the from_zarr() methods are correctly typed for sub-classes.

@d-v-b
Copy link
Collaborator

d-v-b commented Dec 12, 2024

shouldn't we be using Self here?

@dstansby
Copy link
Collaborator Author

I don't think so, because these are classmethods and therefore don't have a self argument. I took this solution from here: python/typing#254 (comment)

@d-v-b
Copy link
Collaborator

d-v-b commented Dec 12, 2024

i think the type checker will resolve Self even in a classmethod. see https://stackoverflow.com/a/76663588

@dstansby
Copy link
Collaborator Author

ooh okay, let me try

@dstansby
Copy link
Collaborator Author

seems to work 👍

d-v-b
d-v-b previously approved these changes Dec 12, 2024
@dstansby
Copy link
Collaborator Author

Woops, I should have fixed the string casting in the latest commit.

@d-v-b
Copy link
Collaborator

d-v-b commented Dec 12, 2024

doctests are failing but that's not due to your changes.

@d-v-b d-v-b merged commit 1bac245 into zarr-developers:main Dec 13, 2024
0 of 4 checks passed
@dstansby
Copy link
Collaborator Author

Any chance of a release with this in? - would help with typing over at ome-zarr-models-py a bit.

@dstansby dstansby deleted the from-zarr-type branch January 13, 2025 18:13
@d-v-b
Copy link
Collaborator

d-v-b commented Jan 13, 2025

sure, I can put out a release tonight or tomorrow

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.

2 participants