code: def _extract_features(
      feature: features_lib.FeatureConnector,
      expected_feature: features_lib.FeatureConnector,
  ) -> features_lib.FeatureConnector:
      """Recursive implementation of `PartialDecoding.extract_features`."""
      # Feature types should match
      if not isinstance(feature, type(expected_feature)):
          raise TypeError(
              f"Expected: {expected_feature}. Got: {feature}"
          )
  
      # Recurse into FeaturesDict, Sequence
      # Use `type` rather than `isinstance` to not recurse into inherited classes.
      if (
          type(feature) == features_lib.FeaturesDict
      ):  # pylint: disable=unidiomatic-typecheck
          expected_feature = typing.cast(
              features_lib.FeaturesDict, expected_feature
          )
          return features_lib.FeaturesDict(
              {  # Extract the feature subset  # pylint: disable=g-complex-comprehension
                  k: _extract_feature_item(  # pytype: disable=wrong-arg-types  # always-use-return-annotations
                      feature=feature,
                      expected_key=k,
                      expected_value=v,
                      fn=_extract_features,
                  )
                  for k, v in expected_feature.items()
              }
          )
      elif (
          type(feature) == features_lib.Sequence
      ):  # pylint: disable=unidiomatic-typecheck
          feature = typing.cast(features_lib.Sequence, feature)
          expected_feature = typing.cast(
              features_lib.Sequence, expected_feature
          )
          feature_subset = _extract_features(
              feature=feature.feature,
              expected_feature=expected_feature.feature,
          )
          return features_lib.Sequence(
              feature_subset, length=feature._length
          )  # pylint: disable=protected-access
      else:
          # Assert that the specs matches
          if (
              feature.dtype != expected_feature.dtype
              or not utils.shapes_are_compatible(
                  feature.shape, expected_feature.shape
              )
          ):
              raise ValueError(
                  f"Expected: {expected_feature}. Got: {feature}"
              )
          return feature
  
file_path: datasets/tensorflow_datasets/core/decode/partial_decode.py
imports: import typing
  from typing import Any, Callable, Optional, Union
  from tensorflow_datasets.core import features
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.decode import base
  from tensorflow_datasets.core.features import features_dict
  from tensorflow_datasets.core.utils import dtype_utils
label_desc: Use image node_id 3 for calling a global function with example usage: _extract_features(feature, expected_feature) and returns: features_lib, features_lib, feature