input: from typing import List
  
  def generate_password(pwd_length: int, include_special_chars: bool = True) -> str:
      """
      Generate a random password of a specified length, including alphanumeric characters
      and optionally at least one special character.
  
      >>> generate_password(8, True)
      'aB3$dF7#'
      >>> generate_password(6, False)
      '1eR5tY'
      """
      chars = string.ascii_letters + string.digits
      if include_special_chars:
          chars += string.punctuation
  
      password = ''.join(random.choice(chars) for _ in range(pwd_length))
      
      if include_special_chars:
          if any([char in string.punctuation for char in password]):
              return password
          else:
              return generate_password(pwd_length, include_special_chars)
  
      return password
output:     import string
      import random
  
      chars = string.ascii_letters + string.digits
      if include_special_chars:
          chars += string.punctuation
  
      password = ''.join(random.choice(chars) for _ in range(pwd_length))
      
      if include_special_chars:
          if any([char in string.punctuation for char in password]):
              return password
          else:
              return generate_password(pwd_length, include_special_chars)
  
      return password