# Why Python allows classes to inherit the class with exact same name?

**URL:** <https://discuss.python.org/t/why-python-allows-classes-to-inherit-the-class-with-exact-same-name/13284>\
**Category:** Python Help\
**Created:** [January 22, 2022, 3:27pm UTC](https://discuss.python.org/t/why-python-allows-classes-to-inherit-the-class-with-exact-same-name/13284 "2022-01-22T15:27:54Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![komoto48g](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/komoto48g/32/6978_2.png) [@komoto48g](https://discuss.python.org/u/komoto48g)\
**Post date:** [January 24, 2022, 1:12pm UTC](https://discuss.python.org/t/why-python-allows-classes-to-inherit-the-class-with-exact-same-name/13284/8 "2022-01-24T13:12:59Z")

</div>

> [@cameron](#):
>
> ```auto
> import foo
> 
> class A(foo.A):
> 
> ```

Yes, it’s practical and easy to read. In contrast, using the same class name (without module name) is very confusing.

> [@kpfleming](#):
>
> C++ forbids redefinition of any types, not just this type of inheritance. The error message you pasted isn’t related to inheritance at all, it’s telling you are trying to redefine `A`.

Exactly! Thanks, I didn’t notice that point. (If I can say in addition, ‘redefinition _in the same scope_’)  
It is not so simple to compare different languages.

> [@tjol](#):
>
> There is one key difference here: in Python, `x = x * 2` rebinds the _name_ `x` to a new object, the result of `x * 2` . In C++, the _object_ named `x` is assigned the value `x * 2`

Yes. It reminded me of this post ([+= should be the same as = + but its giving me error (list) - #4 by sweeneyde](https://discuss.python.org/t/should-be-the-same-as-but-its-giving-me-error-list/12034/4))

---

_[View the full topic](https://discuss.python.org/t/why-python-allows-classes-to-inherit-the-class-with-exact-same-name/13284)._
