from larvae.base import LarvaeBase


class Person(LarvaeBase):
    """
    Details for a Person in Popolo format.
    """

    _schema_name = "person"

    __slots__ = ('name', '_id', 'gender', 'birth_date',
                 'death_date', 'image', 'summary', 'biography', 'links',
                 'other_names', 'extras', 'contact_details', 'openstates_id',
                 'chamber', 'district')
    _other_name_slots = ('name', 'start_date', 'end_date', 'note')

    def __init__(self, name, **kwargs):
        super(Person, self).__init__()
        self.name = name
        for k, v in kwargs.items():
            setattr(self, k, v)

        self.links = []
        self.other_names = []
        self.extras = {}

    def add_name(self, name, **kwargs):
        other_name = {'name': name}
        for k, v in kwargs.items():
            if k not in self._other_name_slots:
                raise AttributeError('{0} not a valid kwarg for add_name'
                                     .format(k))
            other_name[k] = v
        self.other_names.append(other_name)

    def add_link(self, url, note):
        self.links.append({"note": note, "url": url})

    def __unicode__(self):
        return self.name
    __str__ = __unicode__

from larvae.base import LarvaeBase


class Person(LarvaeBase):
    """
    Details for a Person in Popolo format.
    """

    _schema_name = "person"

    __slots__ = ('name', '_id', 'gender', 'birth_date',
                 'death_date', 'image', 'summary', 'biography', 'links',
                 'other_names', 'extras', 'contact_details', 'openstates_id',
                 'chamber', 'district')
    _other_name_slots = ('name', 'start_date', 'end_date', 'note')

    def __init__(self, name, **kwargs):
        super(Person, self).__init__()
        self.name = name
        self.links = []
        self.other_names = []
        self.extras = {}
        for k, v in kwargs.items():
            setattr(self, k, v)

    def add_name(self, name, **kwargs):
        other_name = {'name': name}
        for k, v in kwargs.items():
            if k not in self._other_name_slots:
                raise AttributeError('{0} not a valid kwarg for add_name'
                                     .format(k))
            other_name[k] = v
        self.other_names.append(other_name)

    def add_link(self, url, note):
        self.links.append({"note": note, "url": url})

    def __unicode__(self):
        return self.name
    __str__ = __unicode__

Move default value assignments before kwargs
Move default value assignments before kwargs

  from larvae.base import LarvaeBase
  
  
  class Person(LarvaeBase):
      """
      Details for a Person in Popolo format.
      """
  
      _schema_name = "person"
  
      __slots__ = ('name', '_id', 'gender', 'birth_date',
                   'death_date', 'image', 'summary', 'biography', 'links',
                   'other_names', 'extras', 'contact_details', 'openstates_id',
                   'chamber', 'district')
      _other_name_slots = ('name', 'start_date', 'end_date', 'note')
  
      def __init__(self, name, **kwargs):
          super(Person, self).__init__()
          self.name = name
-         for k, v in kwargs.items():
-             setattr(self, k, v)
- 
          self.links = []
          self.other_names = []
          self.extras = {}
+         for k, v in kwargs.items():
+             setattr(self, k, v)
  
      def add_name(self, name, **kwargs):
          other_name = {'name': name}
          for k, v in kwargs.items():
              if k not in self._other_name_slots:
                  raise AttributeError('{0} not a valid kwarg for add_name'
                                       .format(k))
              other_name[k] = v
          self.other_names.append(other_name)
  
      def add_link(self, url, note):
          self.links.append({"note": note, "url": url})
  
      def __unicode__(self):
          return self.name
      __str__ = __unicode__
  
Move default value assignments before kwargs
## Code Before:
from larvae.base import LarvaeBase


class Person(LarvaeBase):
    """
    Details for a Person in Popolo format.
    """

    _schema_name = "person"

    __slots__ = ('name', '_id', 'gender', 'birth_date',
                 'death_date', 'image', 'summary', 'biography', 'links',
                 'other_names', 'extras', 'contact_details', 'openstates_id',
                 'chamber', 'district')
    _other_name_slots = ('name', 'start_date', 'end_date', 'note')

    def __init__(self, name, **kwargs):
        super(Person, self).__init__()
        self.name = name
        for k, v in kwargs.items():
            setattr(self, k, v)

        self.links = []
        self.other_names = []
        self.extras = {}

    def add_name(self, name, **kwargs):
        other_name = {'name': name}
        for k, v in kwargs.items():
            if k not in self._other_name_slots:
                raise AttributeError('{0} not a valid kwarg for add_name'
                                     .format(k))
            other_name[k] = v
        self.other_names.append(other_name)

    def add_link(self, url, note):
        self.links.append({"note": note, "url": url})

    def __unicode__(self):
        return self.name
    __str__ = __unicode__

## Instruction:
Move default value assignments before kwargs
## Code After:
from larvae.base import LarvaeBase


class Person(LarvaeBase):
    """
    Details for a Person in Popolo format.
    """

    _schema_name = "person"

    __slots__ = ('name', '_id', 'gender', 'birth_date',
                 'death_date', 'image', 'summary', 'biography', 'links',
                 'other_names', 'extras', 'contact_details', 'openstates_id',
                 'chamber', 'district')
    _other_name_slots = ('name', 'start_date', 'end_date', 'note')

    def __init__(self, name, **kwargs):
        super(Person, self).__init__()
        self.name = name
        self.links = []
        self.other_names = []
        self.extras = {}
        for k, v in kwargs.items():
            setattr(self, k, v)

    def add_name(self, name, **kwargs):
        other_name = {'name': name}
        for k, v in kwargs.items():
            if k not in self._other_name_slots:
                raise AttributeError('{0} not a valid kwarg for add_name'
                                     .format(k))
            other_name[k] = v
        self.other_names.append(other_name)

    def add_link(self, url, note):
        self.links.append({"note": note, "url": url})

    def __unicode__(self):
        return self.name
    __str__ = __unicode__
