Fix RecursionError in _compute_mro() on circular class hierarchies (#2968)

* Fix circular MRO from name rebinding without raising errors

When a module-level name is rebound to a subclass of itself
(e.g. pdb.Pdb = CustomPdb where CustomPdb inherits from pdb.Pdb),
_infer_last follows the rebinding and returns the subclass as its
own base, causing infinite recursion in _compute_mro.

Instead of suppressing the RecursionError, resolve the cycle in
_inferred_bases by detecting when the inferred base is the class
itself and falling back to the first non-circular inferred value
from the base expression. This produces the correct MRO without
raising any errors.

Fixes #2967

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
3 files changed