Skip to content

Invalid argument type on type checking if zarr arrays within groups are sliced #3664

@blackblitz

Description

@blackblitz

Zarr version

3.1.5

Numcodecs version

0.16.5

Python Version

3.13.9

Operating System

Linux

Installation

uv

Description

When zarr arrays within groups are sliced, type checking with ty produces an invalid-argument-type error. It is expected to produce no such error.

Steps to reproduce

Here is a minimal example to reproduce the error:

import numpy as np
import zarr
from zarr.storage import MemoryStore

store = MemoryStore()
group = zarr.create_group(store, path="group")
array = group.create_array(name="array", data=np.arange(10))
array = group["array"]
array = np.asarray(array[:5])
print(array)

Running ty check produces the following:

error[invalid-argument-type]: Method `__getitem__` of type `bound method Group.__getitem__(path: str) -> Array[Any] | Group` cannot be called with key of type `slice[None, Literal[5], None]` on object of type `Group`
  --> test.py:9:20
   |
 7 | array = group.create_array(name="array", data=np.arange(10))
 8 | array = group["array"]
 9 | array = np.asarray(array[:5])
   |                    ^^^^^
10 | print(array)
   |
info: rule `invalid-argument-type` is enabled by default

Found 1 diagnostic

Running the script produces the expected output:

[0 1 2 3 4]

Additional output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions