quixadhal

another setter

Aug 7th, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. @equips_to.setter
  2. # No default on slot so the caller MUST supply something.
  3. # Default of the equippable flag is True, because the
  4. # caller will eithe rwant to set or clear that status.
  5. def equips_to(self, slot, is_equippable=True):
  6.     # assume self._equips_to is already initialized to
  7.     # a valid set by being loaded, or set to an empty
  8.     # set in __init__.
  9.     if type(slot) is set:
  10.         if is_equippable:
  11.             # When will self ever NOT be an item?
  12.             #if self.is_item:
  13.             self._equips_to |= slot
  14.         else:
  15.             self._equips_to -= slot
  16.     elif type(slot) is str:
  17.         if slot in equips_to_strings.keys():
  18.             if is_equippable:
  19.                 self._equips_to.add(slot)
  20.             else:
  21.                 self._equips_to.discard(slot)
  22.         else:
  23.             raise ValueError('Invalid slot name %r for %r' % (slot, self))
  24.     else:
  25.         raise TypeError('slot must be a set or a string, not %r' % type(slot))
Advertisement
Add Comment
Please, Sign In to add comment