python exceptions with same name but different subclassing
<p>I am reading the <a href="https://docs.python.org/2/library/exceptions.html" rel="nofollow">python doc</a> and it mentions that </p>

<blockquote>
  <p>Two exception classes that are not related via subclassing are never equivalent, even if they have the same name.</p>
</blockquote>

<p>I'm not sure why it is possible to have two exception classes with the same name but different subclassing. Shouldn't some kind of error/warning be generated in that case?</p>

<p>Exceptions are just specific types of classes. Class names are simply what they are defined as. Forbidding classes to have the same name would brake lots of coding schemes. One such example actually works on exceptions: programs that need to be backwards compatible with python2.6 will often override <code>subprocess.CalledProcessError</code> to conform to the python2.7/3.X interface.</p>

<p>How can you have two exceptions of the same name but different subclassing? You are for example free to do the following:</p>

<pre><code>class ExceptoPatronum(KeyError):
    pass

KExcept = ExceptoPatronum

class ExceptoPatronum(OSError):
    pass

OExcept = ExceptoPatronum
</code></pre>

<p>The classes are named the same but neither equal nor instances of each other:</p>

<pre><code>print(KExcept.__name__)
print(OExcept.__name__)
print(KExcept == OExcept, KExcept is OExcept)
</code></pre>

<p>This is a (contrived) example that runs even with just one file. However, imagine you have two separate modules which each define their own custom class with the same name, let's say <code>ResourceUnavailable</code>.</p>

<p>As long as they are separate, why should users be warned about such internals? If another module relies on both, would you require it to replace them? It would be a nightmare to track such name collisions.</p>

python exception