Repository: Project-MONAI/MONAI
File: monai/inferers/merger.py (Python)

Code before:
        count_store: zarr.storage.Store | str | None = None,
        compressor: str | None = None,
        value_compressor: str | None = None,
        count_compressor: str | None = None,
        chunks: Sequence[int] | bool = True,
        thread_locking: bool = True,
    ) -> None:
        super().__init__(merged_shape=merged_shape, cropped_shape=cropped_shape)
        if not self.merged_shape:
            raise ValueError(f"`merged_shape` must be provided for `ZarrAvgMerger`. {self.merged_shape} is give.")
        self.output_dtype = dtype
        self.value_dtype = value_dtype
        self.count_dtype = count_dtype
        self.store = store
        if version_geq(get_package_version("zarr"), "3.0.0"):
            if value_store is None:
                tmpdir = TemporaryDirectory()
                self.value_store = zarr.storage.LocalStore(tmpdir.name)
            else:
                self.value_store = value_store
            if count_store is None:
                tmpdir = TemporaryDirectory()
                self.count_store = zarr.storage.LocalStore(tmpdir.name)
            else:
                self.count_store = count_store
        else:
            self.value_store = zarr.storage.TempStore() if value_store is None else value_store
            self.count_store = zarr.storage.TempStore() if count_store is None else count_store
        self.chunks = chunks
        self.compressor = compressor
        self.value_compressor = value_compressor
        self.count_compressor = count_compressor
        self.output = zarr.empty(
            shape=self.merged_shape,
            chunks=self.chunks,
            dtype=self.output_dtype,
            compressor=self.compressor,
            store=self.store,
            overwrite=True,
        )
        self.values = zarr.zeros(
            shape=self.merged_shape,
            chunks=self.chunks,
            dtype=self.value_dtype,
            compressor=self.value_compressor,
            store=self.value_store,
            overwrite=True,
        )
        self.counts = zarr.zeros(
            shape=self.merged_shape,
            chunks=self.chunks,

Review comment (suggestion):
```suggestion
        if version_geq(get_package_version("zarr"), "3.0.0"):
            if value_store is None:
                self.tmpdir = TemporaryDirectory()
                self.value_store = zarr.storage.LocalStore(self.tmpdir.name)
            else:
                self.value_store = value_store
            if count_store is None:
                self.tmpdir = TemporaryDirectory()
                self.count_store = zarr.storage.LocalStore(self.tmpdir.name)
            else:
                self.count_store = count_store
        else:
            self.tmpdir = None
```

What I meant was that the lifecycle of the tmpdir object should follow that of the containing object since this will be the same as that for the storage objects.

Code after:
        count_store: zarr.storage.Store | str | None = None,
        compressor: str | None = None,
        value_compressor: str | None = None,
        count_compressor: str | None = None,
        chunks: Sequence[int] | bool = True,
        thread_locking: bool = True,
    ) -> None:
        super().__init__(merged_shape=merged_shape, cropped_shape=cropped_shape)
        if not self.merged_shape:
            raise ValueError(f"`merged_shape` must be provided for `ZarrAvgMerger`. {self.merged_shape} is give.")
        self.output_dtype = dtype
        self.value_dtype = value_dtype
        self.count_dtype = count_dtype
        self.store = store
        self.tmpdir: TemporaryDirectory | None
        if version_geq(get_package_version("zarr"), "3.0.0"):
            if value_store is None:
                self.tmpdir = TemporaryDirectory()
                self.value_store = zarr.storage.LocalStore(self.tmpdir.name)
            else:
                self.value_store = value_store
            if count_store is None:
                self.tmpdir = TemporaryDirectory()
                self.count_store = zarr.storage.LocalStore(self.tmpdir.name)
            else:
                self.count_store = count_store
        else:
            self.tmpdir = None
            self.value_store = zarr.storage.TempStore() if value_store is None else value_store
            self.count_store = zarr.storage.TempStore() if count_store is None else count_store
        self.chunks = chunks
        self.compressor = compressor
        self.value_compressor = value_compressor
        self.count_compressor = count_compressor
        self.output = zarr.empty(
            shape=self.merged_shape,
            chunks=self.chunks,
            dtype=self.output_dtype,
            compressor=self.compressor,
            store=self.store,
            overwrite=True,
        )
        self.values = zarr.zeros(
            shape=self.merged_shape,
            chunks=self.chunks,
            dtype=self.value_dtype,
            compressor=self.value_compressor,
            store=self.value_store,
            overwrite=True,
        )
        self.counts = zarr.zeros(