from djoser.conf import settings

try:
    from django.contrib.auth.password_validation import validate_password
except ImportError:
    from password_validation import validate_password

__all__ = ['settings', 'validate_password']


def get_user_email(user):
    email_field_name = get_user_email_field_name(user)
    return getattr(user, email_field_name, None)


def get_user_email_field_name(user):
    try:  # Assume we are Django >= 1.11
        return user.get_email_field_name()
    except AttributeError:  # we are using Django < 1.11
        return settings.USER_EMAIL_FIELD_NAME

from djoser.conf import settings

try:
    from django.contrib.auth.password_validation import validate_password
except ImportError:  # pragma: no cover
    from password_validation import validate_password

__all__ = ['settings', 'validate_password']


def get_user_email(user):
    email_field_name = get_user_email_field_name(user)
    return getattr(user, email_field_name, None)


def get_user_email_field_name(user):
    try:  # Assume we are Django >= 1.11
        return user.get_email_field_name()
    except AttributeError:  # we are using Django < 1.11
        return settings.USER_EMAIL_FIELD_NAME

Fix invalid fallback leading to circular calls
Fix invalid fallback leading to circular calls

Remove redundant finally

  from djoser.conf import settings
  
  try:
      from django.contrib.auth.password_validation import validate_password
- except ImportError:
+ except ImportError:  # pragma: no cover
      from password_validation import validate_password
  
  __all__ = ['settings', 'validate_password']
  
  
  def get_user_email(user):
      email_field_name = get_user_email_field_name(user)
      return getattr(user, email_field_name, None)
  
  
  def get_user_email_field_name(user):
      try:  # Assume we are Django >= 1.11
          return user.get_email_field_name()
      except AttributeError:  # we are using Django < 1.11
          return settings.USER_EMAIL_FIELD_NAME
  
Fix invalid fallback leading to circular calls
## Code Before:
from djoser.conf import settings

try:
    from django.contrib.auth.password_validation import validate_password
except ImportError:
    from password_validation import validate_password

__all__ = ['settings', 'validate_password']


def get_user_email(user):
    email_field_name = get_user_email_field_name(user)
    return getattr(user, email_field_name, None)


def get_user_email_field_name(user):
    try:  # Assume we are Django >= 1.11
        return user.get_email_field_name()
    except AttributeError:  # we are using Django < 1.11
        return settings.USER_EMAIL_FIELD_NAME

## Instruction:
Fix invalid fallback leading to circular calls
## Code After:
from djoser.conf import settings

try:
    from django.contrib.auth.password_validation import validate_password
except ImportError:  # pragma: no cover
    from password_validation import validate_password

__all__ = ['settings', 'validate_password']


def get_user_email(user):
    email_field_name = get_user_email_field_name(user)
    return getattr(user, email_field_name, None)


def get_user_email_field_name(user):
    try:  # Assume we are Django >= 1.11
        return user.get_email_field_name()
    except AttributeError:  # we are using Django < 1.11
        return settings.USER_EMAIL_FIELD_NAME
