Skip to content
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

docs imprecise: temporary_volume_layer_copy doesn't return an iterable #962

Open
boergens opened this issue Nov 1, 2023 · 2 comments
Open
Labels

Comments

@boergens
Copy link

boergens commented Nov 1, 2023

the documentation says it should return an iterable
https://docs.webknossos.org/api/webknossos/annotation/annotation.html#Annotation.temporary_volume_layer_copy

print(hasattr(a.temporary_volume_layer_copy('Volume'),'__iter__'))
-> False
@boergens boergens added the bug label Nov 1, 2023
@hotzenklotz
Copy link
Member

Well it's returning a Generator from within a with context. So the correct type might be a GeneratorContextManager.

In any case, the preferred way of using this roughly:

    annotation = wk.Annotation.load(
        <some_path>
    )

    volume_names = sorted(annotation.get_volume_layer_names())

    with annotation.temporary_volume_layer_copy(
        volume_layer_name=volume_names[0]
    ) as layer:

       voxels = layer.get_finest_mag().read(
         ...
        )

@hotzenklotz
Copy link
Member

Reading further in this the recommended annotation for generators are Iterator or Generator. See mypy docs: https://mypy.readthedocs.io/en/stable/kinds_of_types.html#generators

Perhaps, the fact that the function is wrapped in a @contextmanager annotation/wrapper might no be properly be picked up by the documentation tool.

@fm3 fm3 changed the title temporary_volume_layer_copy doesn't return an iterable docs imprecise: temporary_volume_layer_copy doesn't return an iterable Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants