You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/gvanrossum'closed_at=<Date2012-07-29.19:01:53.589>created_at=<Date2002-11-05.17:56:34.000>labels= ['interpreter-core']
title='Nested class __name__'updated_at=<Date2012-07-29.19:01:53.589>user='https://github.com/gvanrossum'
Default repr on nested classes produce specious results.
The problem become pratical when you have two nested classes C1.D and C2.D in module m, which end up being both "m.D" in exception traceback.
Classes nested in function are likely to contain some information from the function arguments and are thus different on each function call, making it impossible to have a general way to name them. Thus I propose embedding the resulting class's id in name, like what i'm doing manually in a hulking way:
>>> deffactory(foo):
... classC(object):
... bar = foo
... func_name ='factory'
... C.__name__='%s generated classobj at 0x%x'% (func_name, id(C))
... return C
...
>>> factory(0)
<class '__main__.factory generated classobj at 0x32273c0'>
>>> factory(0)
<class '__main__.factory generated classobj at 0x32245b0'>
Activity
gvanrossum commentedon Nov 5, 2002
The __name__ attribute of a nested class should be set
to 'outer.inner', both for classic and for new-style
classes. E.g.
gvanrossum commentedon Nov 14, 2002
Logged In: YES
user_id=6380
Hm, but should this also be done for functions inside
classes? E.g.
assert C.foo.__name__ == "C.foo"
assert C.__dict__["foo"].__name__ == "C.foo"
And what about classes inside functions?
assert f().__name__ == "f.C"
???
gvanrossum commentedon Feb 11, 2003
Logged In: YES
user_id=6380
I'm less sure I even want this now, and not at all sure how
to do it any more, so lowering priority.
birkenfeld commentedon Mar 10, 2007
Any interest for Python 3000 on this? Otherwise we can close it.
gvanrossum commentedon Mar 10, 2007
I don't think so. Closing.
xiaq commentedon Jul 29, 2012
There is a bigger problem:
Default repr on nested classes produce specious results.
The problem become pratical when you have two nested classes C1.D and C2.D in module m, which end up being both "m.D" in exception traceback.
Classes nested in function are likely to contain some information from the function arguments and are thus different on each function call, making it impossible to have a general way to name them. Thus I propose embedding the resulting class's
idin name, like what i'm doing manually in a hulking way:Please consider reopening this issue.
mstefanro commentedon Jul 29, 2012
Only an issue in Python2.
>>> A.B.__qualname__ 'A.B' >>> repr(A.B) "<class '__main__.A.B'>"