classification
Title: Namespace inconsistency
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Antoine d'Otreppe, benjamin.peterson, georg.brandl, loewis, terry.reedy
Priority: low Keywords:

Created on 2008-10-10 21:35 by Antoine d'Otreppe, last changed 2008-10-17 22:38 by terry.reedy. This issue is now closed.

Messages (5)
msg74648 - (view) Author: Antoine d'Otreppe (Antoine d'Otreppe) Date: 2008-10-10 21:35
Hello

See the following code and comments for explanation ;) (Try it with
interactive mode)

---
>>> class A:
...     class B:
...         pass

>>> A
<class __main__.A at 0x...>
>>> A.B
<class __main__.B at 0x...>
>>> B
NameError: B is not defined
---

This seems to be inconsistent, as Python represents A.B as __main__.B,
but B is not accessable from __main__

Maybe this could be better:
---
>>> A.B
<class __main__.A.B at 0x...>
                  ^
---
msg74649 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-10 21:40
This is because type_repr looks at the __module__ attribute to determine
the location. Fixing this would probably require adding a
__nestedclass__ attribute. However, nested classes aren't used very
much, so it's not urgent by any means.
msg74672 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-10-12 17:23
I'm tempted to close this as "won't fix".
msg74673 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-10-12 17:34
Me too. There are too many cases where class statements can be executed
to get this right.
msg74944 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-10-17 22:38
I consider the request invalid.  Continue the example with
B=A.B
B
The repr of an object cannot now and should not depend on the access path.
=or=
class C: pass
class D: pass
D
C.D = D
C.D
Same comment.
History
Date User Action Args
2008-10-17 22:38:19terry.reedysetnosy: + terry.reedy
messages: + msg74944
2008-10-12 18:03:37loewissetstatus: open -> closed
2008-10-12 17:34:38georg.brandlsetnosy: + georg.brandl
messages: + msg74673
2008-10-12 17:23:01loewissetresolution: wont fix
messages: + msg74672
nosy: + loewis
2008-10-10 21:40:50benjamin.petersonsetpriority: low
nosy: + benjamin.peterson
messages: + msg74649
2008-10-10 21:35:35Antoine d'Otreppecreate