diff --git a/tensorflow_datasets/core/as_dataframe.py b/tensorflow_datasets/core/as_dataframe.py index 4536e961bfd..f4f61f1fd03 100644 --- a/tensorflow_datasets/core/as_dataframe.py +++ b/tensorflow_datasets/core/as_dataframe.py @@ -111,11 +111,11 @@ def _get_feature( if type(feature) != features.Sequence and not path: # pylint: disable=unidiomatic-typecheck break sequence_rank += 1 - feature = feature.feature # Extract inner feature # pytype: disable=attribute-error + feature = feature.feature # Extract inner feature if path: # Has level deeper, recurse feature = typing.cast(features.FeaturesDict, feature) - feature, nested_sequence_rank = _get_feature(path[1:], feature[path[0]]) # pytype: disable=wrong-arg-types + feature, nested_sequence_rank = _get_feature(path[1:], feature[path[0]]) sequence_rank += nested_sequence_rank return feature, sequence_rank @@ -186,7 +186,7 @@ class StyledDataFrame(pd.DataFrame): # selecting sub-data frames. def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) # pytype: disable=wrong-arg-count # re-none + super().__init__(*args, **kwargs) # Use name-mangling for forward-compatibility in case pandas # adds a `_styler` attribute in the future. self.__styler: Optional[Styler] = None @@ -195,13 +195,13 @@ def __init__(self, *args, **kwargs): def current_style(self) -> Styler: """Like `pandas.DataFrame.style`, but attach the style to the DataFrame.""" if self.__styler is None: - self.__styler = super().style # pytype: disable=attribute-error # re-none + self.__styler = super().style return self.__styler def _repr_html_(self) -> Union[None, str]: # See base class for doc if self.__styler is None: - return super()._repr_html_() # pytype: disable=attribute-error # re-none + return super()._repr_html_() return self.__styler._repr_html_() # pylint: disable=protected-access # Pack `as_supervised=True` datasets diff --git a/tensorflow_datasets/core/dataset_builder.py b/tensorflow_datasets/core/dataset_builder.py index 02a21b3d695..bff5c2f70df 100644 --- a/tensorflow_datasets/core/dataset_builder.py +++ b/tensorflow_datasets/core/dataset_builder.py @@ -1478,7 +1478,7 @@ def _get_filename_template( split=split_name, dataset_name=self.name, data_dir=self.data_path, - filetype_suffix=self.info.file_format.file_suffix, # pytype: disable=attribute-error + filetype_suffix=self.info.file_format.file_suffix, ) @@ -1806,7 +1806,7 @@ def _generate_splits( # Finalize the splits (after apache beam completed, if it was used) return [future.result() for future in split_info_futures] - def _download_and_prepare( # pytype: disable=signature-mismatch # overriding-parameter-type-checks + def _download_and_prepare( # pyrefly: ignore[bad-override] self, dl_manager: download.DownloadManager, download_config: download.DownloadConfig, @@ -1931,7 +1931,7 @@ def _download_and_prepare( ) -> None: download_config = download_config or download.DownloadConfig() - split_builder = split_builder_lib.SplitBuilder( # pytype: disable=wrong-arg-types + split_builder = split_builder_lib.SplitBuilder( split_dict=self.info.splits, features=self.info.features, dataset_size=self.info.dataset_size, diff --git a/tensorflow_datasets/core/dataset_info.py b/tensorflow_datasets/core/dataset_info.py index 97d3233b4cd..4ee423af83c 100644 --- a/tensorflow_datasets/core/dataset_info.py +++ b/tensorflow_datasets/core/dataset_info.py @@ -420,7 +420,7 @@ def set_nondeterministic_order(self, nondeterministic_order: bool) -> None: def homepage(self) -> str: urls = self.as_proto.location.urls tfds_homepage = f"https://www.tensorflow.org/datasets/catalog/{self.name}" - return urls and urls[0] or tfds_homepage # pytype: disable=bad-return-type + return urls and urls[0] or tfds_homepage # pyrefly: ignore[bad-return] @property def citation(self) -> str: @@ -726,7 +726,7 @@ def read_from_directory(self, dataset_info_dir: epath.PathLike) -> None: ) # Update splits - filename_template = naming.ShardedFileTemplate( # pytype: disable=wrong-arg-types # always-use-property-annotation + filename_template = naming.ShardedFileTemplate( dataset_name=self.name, data_dir=self.data_dir, # pyrefly: ignore[bad-argument-type] filetype_suffix=parsed_proto.file_format or "tfrecord", @@ -1202,7 +1202,7 @@ def pack_as_supervised_ds( and isinstance(ds.element_spec, tuple) and len(ds.element_spec) == 2 ): - x_key, y_key = ds_info.supervised_keys # pytype: disable=bad-unpacking + x_key, y_key = ds_info.supervised_keys # pyrefly: ignore[bad-unpacking] ds = ds.map(lambda x, y: {x_key: x, y_key: y}) return ds else: # If dataset isn't a supervised tuple (input, label), return as-is diff --git a/tensorflow_datasets/core/dataset_utils.py b/tensorflow_datasets/core/dataset_utils.py index 5457cdde9de..b6ed3bd2a73 100644 --- a/tensorflow_datasets/core/dataset_utils.py +++ b/tensorflow_datasets/core/dataset_utils.py @@ -117,7 +117,7 @@ def _elem_to_numpy_eager( ) -> Union[NumpyElem, Iterable[NumpyElem]]: """Converts a single element from tf to numpy.""" if isinstance(tf_el, tf.Tensor): - return tf_el._numpy() # pytype: disable=attribute-error # pylint: disable=protected-access + return tf_el._numpy() # pylint: disable=protected-access elif isinstance(tf_el, tf.RaggedTensor): return tf_el elif isinstance(tf_el, tf.data.Dataset): diff --git a/tensorflow_datasets/core/example_parser.py b/tensorflow_datasets/core/example_parser.py index 92a295bf801..0fbc9293a6a 100644 --- a/tensorflow_datasets/core/example_parser.py +++ b/tensorflow_datasets/core/example_parser.py @@ -130,7 +130,7 @@ def __post_init__(self): def parse_example( self, serialized_example: bytes | memoryview ) -> Mapping[str, Union[np.ndarray, list[Any]]]: - example = tf_example_pb2.Example.FromString(serialized_example) # pyrefly: ignore[bad-argument-type] + example = tf_example_pb2.Example.FromString(serialized_example) np_example = _features_to_numpy(example.features, self._flat_example_specs) # pyrefly: ignore[bad-argument-type] return utils.pack_as_nest_dict(np_example, self.example_specs) diff --git a/tensorflow_datasets/core/features/audio_feature.py b/tensorflow_datasets/core/features/audio_feature.py index ec01ffea117..432d48fc5b0 100644 --- a/tensorflow_datasets/core/features/audio_feature.py +++ b/tensorflow_datasets/core/features/audio_feature.py @@ -357,7 +357,7 @@ def from_json_content( # pyrefly: ignore[bad-override] lazy_decode=value.lazy_decode or False, ) - def to_json_content(self) -> feature_pb2.AudioFeature: # pytype: disable=signature-mismatch # overriding-return-type-checks + def to_json_content(self) -> feature_pb2.AudioFeature: # pyrefly: ignore[bad-override] return feature_pb2.AudioFeature( shape=feature_lib.to_shape_proto(self.shape), dtype=feature_lib.dtype_to_str(self.dtype), # pyrefly: ignore[bad-argument-type] diff --git a/tensorflow_datasets/core/features/bounding_boxes.py b/tensorflow_datasets/core/features/bounding_boxes.py index e74a915e875..02c8c727208 100644 --- a/tensorflow_datasets/core/features/bounding_boxes.py +++ b/tensorflow_datasets/core/features/bounding_boxes.py @@ -152,9 +152,7 @@ def from_json_content( # pyrefly: ignore[bad-override] def to_json_content( # pyrefly: ignore[bad-override] self, - ) -> ( - feature_pb2.BoundingBoxFeature - ): # pytype: disable=signature-mismatch # overriding-return-type-checks + ) -> feature_pb2.BoundingBoxFeature: bbox_format = None if self.bbox_format: bbox_format = ( diff --git a/tensorflow_datasets/core/features/class_label_feature.py b/tensorflow_datasets/core/features/class_label_feature.py index fedf259e3fc..92de3fd56e2 100644 --- a/tensorflow_datasets/core/features/class_label_feature.py +++ b/tensorflow_datasets/core/features/class_label_feature.py @@ -190,7 +190,7 @@ def load_metadata(self, data_dir, feature_name=None) -> Optional[list[str]]: pass def _additional_repr_info(self) -> dict[str, int]: - return {"num_classes": self.num_classes} # pytype: disable=bad-return-type # always-use-property-annotation + return {"num_classes": self.num_classes} # pyrefly: ignore[bad-assignment] def repr_html(self, ex: int) -> str: # pyrefly: ignore[bad-override] """Class labels are displayed with their name.""" @@ -209,7 +209,7 @@ def from_json_content( # pyrefly: ignore[bad-override] return cls(**value) # pyrefly: ignore[bad-argument-type] return cls(num_classes=value.num_classes) - def to_json_content(self) -> feature_pb2.ClassLabel: # pytype: disable=signature-mismatch # overriding-return-type-checks + def to_json_content(self) -> feature_pb2.ClassLabel: # pyrefly: ignore[bad-override] return feature_pb2.ClassLabel(num_classes=self.num_classes) @classmethod diff --git a/tensorflow_datasets/core/features/feature.py b/tensorflow_datasets/core/features/feature.py index a8ee6d0c0c4..d00bb5647cb 100644 --- a/tensorflow_datasets/core/features/feature.py +++ b/tensorflow_datasets/core/features/feature.py @@ -409,7 +409,7 @@ def cls_from_name(cls, python_class_name: str) -> Type['FeatureConnector']: raise ValueError( f'Python class name must contain a dot, got: "{python_class_name}"' ) - module_name, _ = python_class_name.rsplit('.', maxsplit=1) # pytype: disable=attribute-error + module_name, _ = python_class_name.rsplit('.', maxsplit=1) try: # Import to register the FeatureConnector importlib.import_module(module_name) @@ -570,7 +570,7 @@ def from_json_content( """ if not isinstance(value, dict): raise TypeError(f'Unexpected feature connector value: {value!r}') - return cls(doc=doc, **value) # pytype: disable=not-instantiable + return cls(doc=doc, **value) def to_json_content(self) -> Union[Json, message.Message]: """FeatureConnector factory (to overwrite). @@ -1104,7 +1104,7 @@ def _has_shape_ambiguity(in_shape: Shape, out_shape: Shape) -> bool: """Returns True if the shape can be an empty sequence with unknown shape.""" # Normalize shape if running with `tf.compat.v1.disable_v2_tensorshape` if isinstance(in_shape, tf.TensorShape): - in_shape = in_shape.as_list() # pytype: disable=attribute-error + in_shape = in_shape.as_list() return bool( in_shape[0] is None # Empty sequence diff --git a/tensorflow_datasets/core/features/image_feature.py b/tensorflow_datasets/core/features/image_feature.py index 75ac9e42a81..b0f4c1913b7 100644 --- a/tensorflow_datasets/core/features/image_feature.py +++ b/tensorflow_datasets/core/features/image_feature.py @@ -417,7 +417,7 @@ def from_json_content( # pyrefly: ignore[bad-override] ) -> 'Image': if isinstance(value, dict): # For backwards compatibility - return cls( # pytype: disable=wrong-arg-types + return cls( shape=tuple(value['shape']), # pyrefly: ignore[bad-argument-type] dtype=feature_lib.dtype_from_str(value['dtype']), # pyrefly: ignore[bad-argument-type] encoding_format=value['encoding_format'], # pyrefly: ignore[bad-argument-type] diff --git a/tensorflow_datasets/core/features/sequence_feature.py b/tensorflow_datasets/core/features/sequence_feature.py index 760ac9cbbc9..c5f0f5b797b 100644 --- a/tensorflow_datasets/core/features/sequence_feature.py +++ b/tensorflow_datasets/core/features/sequence_feature.py @@ -174,10 +174,10 @@ def load_metadata(self, *args, **kwargs): def __getitem__(self, key): """Convenience method to access the underlying features.""" - return self._feature[key] # pytype: disable=unsupported-operands + return self._feature[key] def __contains__(self, key: str) -> bool: - return key in self._feature # pytype: disable=unsupported-operands + return key in self._feature def __getattr__(self, key): """Allow to access the underlying attributes directly.""" @@ -318,5 +318,5 @@ def update_length(elem): # 3. Extract each individual elements return [ utils.map_nested(lambda elem: elem[i], dict_list, dict_only=True) # pylint: disable=cell-var-from-loop - for i in range(length['value']) # pytype: disable=wrong-arg-types + for i in range(length['value']) # pyrefly: ignore[bad-argument-type] ] diff --git a/tensorflow_datasets/core/features/text_feature.py b/tensorflow_datasets/core/features/text_feature.py index d2a3861cdc0..0bdce29e9be 100644 --- a/tensorflow_datasets/core/features/text_feature.py +++ b/tensorflow_datasets/core/features/text_feature.py @@ -139,7 +139,7 @@ def save_metadata(self, data_dir, feature_name: str) -> None: # pyrefly: ignore def load_metadata(self, data_dir, feature_name: str) -> None: # pyrefly: ignore[bad-override] if self._encoder_cls: fname_prefix = _file_name_prefix_for_metadata(feature_name, data_dir) - self._encoder = self._encoder_cls.load_from_file(fname_prefix) # pytype: disable=attribute-error + self._encoder = self._encoder_cls.load_from_file(fname_prefix) return # Error checking: ensure there are no metadata files @@ -209,7 +209,7 @@ def from_json_content( # pyrefly: ignore[bad-override] ) return cls() - def to_json_content(self) -> Union[Json, feature_pb2.TextFeature]: # pytype: disable=signature-mismatch # overriding-return-type-checks + def to_json_content(self) -> Union[Json, feature_pb2.TextFeature]: # pyrefly: ignore[bad-override] if self._encoder: logging.warning( "Dataset is using deprecated text encoder API which will be removed " diff --git a/tensorflow_datasets/core/features/translation_feature.py b/tensorflow_datasets/core/features/translation_feature.py index f9c1c3b0fd0..6bc4e4adaa4 100644 --- a/tensorflow_datasets/core/features/translation_feature.py +++ b/tensorflow_datasets/core/features/translation_feature.py @@ -126,7 +126,7 @@ def from_json_content( # pyrefly: ignore[bad-override] assert not value.variable_languages_per_example return cls(languages=value.languages) - def to_json_content(self) -> feature_pb2.TranslationFeature: # pytype: disable=signature-mismatch # overriding-return-type-checks + def to_json_content(self) -> feature_pb2.TranslationFeature: # pyrefly: ignore[bad-override] if self._encoder or self._encoder_config: raise ValueError( "TFDS encoder are deprecated and will be removed soon. " @@ -249,7 +249,7 @@ def from_json_content( # pyrefly: ignore[bad-override] assert value.variable_languages_per_example return cls(languages=value.languages) - def to_json_content(self) -> feature_pb2.TranslationFeature: # pytype: disable=signature-mismatch # overriding-return-type-checks + def to_json_content(self) -> feature_pb2.TranslationFeature: # pyrefly: ignore[bad-override] return feature_pb2.TranslationFeature( languages=self.languages, variable_languages_per_example=True ) diff --git a/tensorflow_datasets/core/features/video_feature.py b/tensorflow_datasets/core/features/video_feature.py index f0c83264229..dcc49f03566 100644 --- a/tensorflow_datasets/core/features/video_feature.py +++ b/tensorflow_datasets/core/features/video_feature.py @@ -207,7 +207,7 @@ def from_json_content( # pyrefly: ignore[bad-override] ffmpeg_extra_args=value.ffmpeg_extra_args, ) - def to_json_content(self) -> feature_pb2.VideoFeature: # pytype: disable=signature-mismatch # overriding-return-type-checks + def to_json_content(self) -> feature_pb2.VideoFeature: # pyrefly: ignore[bad-override] return feature_pb2.VideoFeature( shape=feature_lib.to_shape_proto(self.shape), dtype=feature_lib.dtype_to_str(self.dtype), # pyrefly: ignore[bad-argument-type] @@ -219,5 +219,5 @@ def to_json_content(self) -> feature_pb2.VideoFeature: # pytype: disable=signat def repr_html(self, ex: np.ndarray) -> str: """Video are displayed as `