          # We can't add it as a class attributes or it would expect an
          # implicit `self` argument to be passed.
          self.reverse = reverse
  
          super(HyperlinkedRelatedField, self).__init__(**kwargs)
  
      def use_pk_only_optimization(self):
          return self.lookup_field == 'pk'
  
      def get_object(self, view_name, view_args, view_kwargs):
 
</s> remove         if output_format is None or isinstance(value, six.string_types):
 </s> add         if output_format is None or isinstance(value, str): </s> remove         class MockQueryset(object):
 </s> add         class MockQueryset: </s> remove         if data == '' or (self.trim_whitespace and six.text_type(data).strip() == ''):
 </s> add         if data == '' or (self.trim_whitespace and str(data).strip() == ''): </s> remove         super(HyperlinkedIdentityField, self).__init__(view_name, **kwargs)
 </s> add         super().__init__(view_name, **kwargs) </s> remove def unicode_repr(instance):
    # Get the repr of an instance, but ensure it is a unicode string
    # on both python 3 (already the case) and 2 (not the case).
    if six.PY2:
        return repr(instance).decode('utf-8')
    return repr(instance)


def unicode_to_repr(value):
    # Coerce a unicode string to the correct repr return type, depending on
    # the Python version. We wrap all our `__repr__` implementations with
    # this and then use unicode throughout internally.
    if six.PY2:
        return value.encode('utf-8')
    return value


 </s> add 
        super().__init__(**kwargs)
          # We can't add it as a class attributes or it would expect an
          # implicit `self` argument to be passed.
          self.reverse = reverse
  
        super().__init__(**kwargs)
  
      def use_pk_only_optimization(self):
          return self.lookup_field == 'pk'
  
      def get_object(self, view_name, view_args, view_kwargs):
keep keep keep keep replace keep keep keep keep keep
 Dropped Python 2 compatibility. (#6615)

Thanks to Jon Dufresne (@jdufresne) for review.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com> 
rest_framework/relations.py