title: Modifying enum class in Python
body: <pre><code>from enum import Enum
  
  class Direction(Enum):
      NORTH = 0
      EAST = 1
      SOUTH = 2
      WEST = 3
  
      def turn_right(self):
          self = Direction((self.value + 1) % 4)
  
  d = Direction.EAST
  print(d)
  d.turn_right()
  print(d)
  d.turn_right()
  print(d)
  </code></pre>
  
  <p>Intended output is supposed to be </p>
  
  <pre><code>Direction.EAST
  Direction.SOUTH
  Direction.WEST
  </code></pre>
  
  <p>after each turn, but what I got instead was just</p>
  
  <pre><code>Direction.EAST
  Direction.EAST
  Direction.EAST
  </code></pre>
  
  <p>Looks like it's not updating <code>self</code>, but why? How can I change the class such that its usage stays the same?</p>
  
  <p>One possible workaround is</p>
  
  <pre><code>    def turn_right(self):
          return Direction((self.value + 1) % 4)
  </code></pre>
  
  <p>but this returns a new <code>Direction</code> everytime, is there a way to make the method work "in-place"?</p>