webknossos-libs icon indicating copy to clipboard operation
webknossos-libs copied to clipboard

docs imprecise: temporary_volume_layer_copy doesn't return an iterable

Open boergens opened this issue 2 years ago • 2 comments

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 avatar Nov 01 '23 18:11 boergens

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 avatar Nov 02 '23 09:11 hotzenklotz

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.

hotzenklotz avatar Nov 02 '23 09:11 hotzenklotz