title: Python - Access to a protected member _ of a class
body: <p>Given a class with some protected members and a public interface to modify them, when is it generally accepted to access the protected members directly? I have some specific examples in mind:</p>
  
  <ol>
  <li>Unit testing</li>
  <li>Internal private methods such as __add__ or __cmp__ accessing other's protected attributes</li>
  <li>Recursive data structures (e.g. accessing next._data in a linked list)</li>
  </ol>
  
  <p>I don't want to make these attributes public as I don't want them touched publicly. My syntax IDE syntax highlighting keeps saying that I'm wrong with accessing protected members - who is right here?</p>
  
  <p><strong>EDIT</strong> - adding a simple example below:</p>
  
  <pre><code>class Complex:
      def __init__(self, imaginary, base):
          self._imaginary = imaginary
          self._base = base
  
      def __str__(self):
          return "%fi + %f" % self._base, self._imaginary
  
      def __add__(self, other):
          return Complex(self._imaginary + other._imaginary, self._base + other._base)
  </code></pre>
  
  <p>Pycharm highlights <em>other._imaginary</em> and <em>other._base</em> with the following:</p>
  
  <blockquote>
    <p>Access to a protected member _imaginary of a class</p>
  </blockquote>