Hey, I just updated to dagster 0.15.0 and saw in c...
# ask-community
Hey, I just updated to dagster 0.15.0 and saw in changelog, that DynamicOutputs should be supported by mypy, could somebody give me an example how that should work? I’m trying:
Copy code
def split_file(path: list[str], split_length: int = 10000) -> DynamicOutput[FileInfo]:
    with open(path[0], encoding="utf-8") as file_handler:
        content = [int(line.strip()) for line in file_handler]
    for chunk in np.array_split(content, math.ceil(len(content) / split_length)):
        filename_hash = hashlib.md5(str(chunk).encode("utf-8")).hexdigest()
        filename = f"{filename_hash}.txt"
        yield DynamicOutput(FileInfo(chunk, filename), mapping_key=filename.replace(".", "_"))
But I still get mypy error:
*error:* The return type of a generator function should be *"Generator"* or one of its supertypes
Hi Tadas. Here's an example of a mypy annotation. You'll need to annotate the return type to be a generator:
Copy code
def my_op_yields_output() -> Generator[DynamicOutput, None, None]:
    for i in range(5):
        yield DynamicOutput(i, mapping_key=str(i))
object in the example above is from the
module: https://docs.python.org/3/library/typing.html#typing.Generator
@claire thanks! 🙂