1- # Copyright 2025 The dataclass_array Authors.
1+ # Copyright 2026 The dataclass_array Authors.
22#
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
@@ -137,7 +137,7 @@ def array_field(
137137 # TODO(epot): Validate shape, dtype
138138 dca_field = _ArrayFieldMetadata (
139139 inner_shape_non_static = shape ,
140- dtype = dtype ,
140+ dtype = dtype , # pyrefly: ignore[bad-argument-type]
141141 )
142142 return dataclasses .field (** field_kwargs , metadata = {_METADATA_KEY : dca_field })
143143
@@ -148,7 +148,7 @@ class MetaDataclassArray(type):
148148 # TODO(b/204422756): We cannot use `__class_getitem__` due to b/204422756
149149 def __getitem__ (cls , spec ):
150150 # Not clear how this would interact if cls is also a `Generic`
151- return Annotated [cls , field_utils .ShapeAnnotation (spec )]
151+ return Annotated [cls , field_utils .ShapeAnnotation (spec )] # pyrefly: ignore[not-a-type]
152152
153153
154154# TODO(epot): Restore once pytype support this
@@ -386,7 +386,7 @@ def __getitem__(self: _DcT, indices: _IndicesArg) -> _DcT:
386386 indices = _to_absolute_indices (indices , shape = self .shape )
387387 return self ._map_field (
388388 array_fn = lambda f : f .value [indices ],
389- dc_fn = lambda f : f .value [indices ],
389+ dc_fn = lambda f : f .value [indices ], # pyrefly: ignore[bad-argument-type]
390390 )
391391
392392 # _DcT[n *d] -> Iterator[_DcT[*d]]
@@ -454,7 +454,7 @@ def fn(ray: Optional[dca.Ray] = None):
454454
455455 def map_field (
456456 self : _DcT ,
457- fn : Callable [[Array ['*din' ]], Array ['*dout' ]],
457+ fn : Callable [[Array ['*din' ]], Array ['*dout' ]], # pyrefly: ignore[not-a-type]
458458 ) -> _DcT :
459459 """Apply a transformation on all arrays from the fields."""
460460 return self ._map_field ( # pylint: disable=protected-access
@@ -659,7 +659,7 @@ def _cast_field(f: _ArrayField) -> None:
659659 new_value = np_utils .asarray (
660660 f .value ,
661661 xnp = xnp ,
662- dtype = f .dtype ,
662+ dtype = f .dtype , # pyrefly: ignore[bad-argument-type]
663663 cast_dtype = self .__dca_params__ .cast_dtype ,
664664 )
665665 self ._setattr (f .name , new_value )
@@ -740,7 +740,7 @@ def _to_absolute_axis(self, axis: Axes) -> Axes:
740740 def _map_field (
741741 self : _DcT ,
742742 * ,
743- array_fn : Callable [[_ArrayField [Array ['*din' ]]], Array ['*dout' ]],
743+ array_fn : Callable [[_ArrayField [Array ['*din' ]]], Array ['*dout' ]], # pyrefly: ignore[not-a-type]
744744 dc_fn : Optional [Callable [[_ArrayField [_DcT ]], _DcT ]],
745745 _inplace : bool = False ,
746746 ) -> _DcT :
@@ -758,7 +758,7 @@ def _map_field(
758758
759759 def _apply_field_dn (f : _ArrayField ):
760760 if f .is_dataclass : # Recurse on dataclasses
761- return dc_fn (f ) # pylint: disable=protected-access
761+ return dc_fn (f ) # pylint: disable=protected-access # pyrefly: ignore[not-callable]
762762 else :
763763 return array_fn (f )
764764
@@ -881,7 +881,7 @@ def _setattr(self, name: str, value: Any) -> None:
881881 """Like setattr, but support `frozen` dataclasses."""
882882 object .__setattr__ (self , name , value )
883883
884- def assert_same_xnp (self , x : Union [Array [...], DataclassArray ]) -> None :
884+ def assert_same_xnp (self , x : Union [Array [...], DataclassArray ]) -> None : # pyrefly: ignore[not-a-type]
885885 """Assert the given array is of the same type as the current object."""
886886 xnp = np_utils .get_xnp (x )
887887 if xnp is not self .xnp :
@@ -942,7 +942,7 @@ def _init_cls(self: DataclassArray) -> None:
942942 # is propagated by the various ops.
943943 dca_fields_metadata [_DUMMY_ARRAY_FIELD ] = _ArrayFieldMetadata ( # pytype: disable=wrong-arg-types
944944 inner_shape_non_static = (),
945- dtype = np .float32 ,
945+ dtype = np .float32 , # pyrefly: ignore[bad-argument-type]
946946 )
947947 default_dummy_array = np .zeros ((), dtype = np .float32 )
948948 _add_field_to_dataclass (
@@ -1032,7 +1032,7 @@ def _to_absolute_indices(indices: _Indices, *, shape: Shape) -> _Indices:
10321032 start_elems = indices [:ellipsis_index ]
10331033 end_elems = indices [ellipsis_index + 1 :]
10341034 ellipsis_replacement = [slice (None )] * (len (shape ) - valid_count )
1035- return (* start_elems , * ellipsis_replacement , * end_elems )
1035+ return (* start_elems , * ellipsis_replacement , * end_elems ) # pyrefly: ignore[bad-return]
10361036
10371037
10381038@dataclasses .dataclass (frozen = True )
@@ -1116,15 +1116,15 @@ def full_shape(self) -> DcOrArrayT:
11161116 """Access the `host.<field-name>.shape`."""
11171117 # TODO(b/198633198): We need to convert to tuple because TF evaluate
11181118 # empty shapes to True `bool(shape) == True` when `shape=()`
1119- return tuple (self .value .shape )
1119+ return tuple (self .value .shape ) # pyrefly: ignore[bad-return, missing-attribute]
11201120
11211121 @functools .cached_property
11221122 def inner_shape (self ) -> Shape :
11231123 """Returns the the static shape resolved for the current value."""
11241124
11251125 if not self .inner_shape_non_static :
11261126 return ()
1127- static_shape = self .full_shape [- len (self .inner_shape_non_static ) :]
1127+ static_shape = self .full_shape [- len (self .inner_shape_non_static ) :] # pyrefly: ignore[unsupported-operation]
11281128
11291129 def err_msg () -> ValueError :
11301130 return ValueError (
@@ -1177,8 +1177,8 @@ def host_shape(self) -> Shape:
11771177 if not self .inner_shape_non_static :
11781178 shape = self .full_shape
11791179 else :
1180- shape = self .full_shape [: - len (self .inner_shape_non_static )]
1181- return shape
1180+ shape = self .full_shape [: - len (self .inner_shape_non_static )] # pyrefly: ignore[unsupported-operation]
1181+ return shape # pyrefly: ignore[bad-return]
11821182
11831183 def assert_shape (self ) -> None :
11841184 if self .host_shape + self .inner_shape != self .full_shape :
@@ -1191,7 +1191,7 @@ def broadcast_to(self, shape: Shape) -> DcOrArrayT:
11911191 """Broadcast the host_shape."""
11921192 final_shape = shape + self .inner_shape
11931193 if self .is_dataclass :
1194- return self .value .broadcast_to (final_shape )
1194+ return self .value .broadcast_to (final_shape ) # pyrefly: ignore[missing-attribute]
11951195 else :
11961196 return self .xnp .broadcast_to (self .value , final_shape )
11971197
@@ -1214,7 +1214,7 @@ def _is_called_inside_torch_vmap() -> bool:
12141214
12151215def _make_field_metadata (
12161216 field : dataclasses .Field [Any ],
1217- hints : dict [str , TypeAlias ],
1217+ hints : dict [str , TypeAlias ], # pyrefly: ignore[invalid-annotation]
12181218) -> Optional [_ArrayFieldMetadata ]:
12191219 """Make the array field class."""
12201220 # TODO(epot): One possible confusion is if user define
@@ -1233,7 +1233,7 @@ def _make_field_metadata(
12331233 return field_metadata
12341234
12351235
1236- def _type_to_field_metadata (hint : TypeAlias ) -> Optional [_ArrayFieldMetadata ]:
1236+ def _type_to_field_metadata (hint : TypeAlias ) -> Optional [_ArrayFieldMetadata ]: # pyrefly: ignore[invalid-annotation]
12371237 """Converts type hint to extract `inner_shape`, `dtype`."""
12381238 array_type = type_parsing .get_array_type (hint )
12391239
0 commit comments