The delete_object_list argument in minio.api.remove_objects was annotated as Iterator[DeleteObject]. This means that mypy would complain if client code passes a list of DeleteObject-s to remove_objects.
But in practice passing in a list works: the delete_objects function converts the list to an iterator using itertools.chain.
I changed the type annotation to Iterable[DeleteObject]. This way, mypy is happy if we pass an iterator, and when we pass a list.
(And same thing in upload_snowball_objects)
Here's a small isolated testcase demonstrating the problem:
from __future__ import annotations
from collections.abc import Iterable
from typing import Iterator
def foo(data: Iterator[int]):
pass
a = [1, 2, 3, 4]
foo(a)
foo(iter(a))
Running mypy on it results in:
experiment.py:13: error: Argument 1 to "foo" has incompatible type "list[int]"; expected "Iterator[int]" [arg-type]
experiment.py:13: note: "list" is missing following "Iterator" protocol member:
experiment.py:13: note: __next__
But if I change the type annotation from Iterator[int] to Iterable[int]:
from __future__ import annotations
from collections.abc import Iterable
from typing import Iterator
def foo(data: Iterable[int]):
pass
a = [1, 2, 3, 4]
foo(a)
foo(iter(a))
The
delete_object_list
argument inminio.api.remove_objects
was annotated asIterator[DeleteObject]
. This means that mypy would complain if client code passes a list ofDeleteObject
-s to remove_objects.But in practice passing in a list works: the
delete_objects
function converts the list to an iterator usingitertools.chain
.I changed the type annotation to
Iterable[DeleteObject]
. This way, mypy is happy if we pass an iterator, and when we pass a list.(And same thing in upload_snowball_objects)
Here's a small isolated testcase demonstrating the problem:
Running mypy on it results in:
But if I change the type annotation from
Iterator[int]
toIterable[int]
:then mypy is happy: