New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested class __name__ #37422
Comments
The __name__ attribute of a nested class should be set >>> class C:
... class C1: pass
...
>>> C.C1.__name__
'C.C1'
>>> |
Logged In: YES Hm, but should this also be done for functions inside class C:
def foo(self): pass assert C.foo.__name__ == "C.foo" And what about classes inside functions? def f():
class C: pass
return C assert f().__name__ == "f.C" ??? |
Logged In: YES I'm less sure I even want this now, and not at all sure how |
Any interest for Python 3000 on this? Otherwise we can close it. |
I don't think so. Closing. |
There is a bigger problem: >>> class C:
... class D:
... pass
...
>>> repr(C)
"<class '__main__.C'>"
>>> repr(C.D)
"<class '__main__.D'>" 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 >>> def factory(foo):
... class C(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'> Please consider reopening this issue. |
Only an issue in Python2. >>> A.B.__qualname__
'A.B'
>>> repr(A.B)
"<class '__main__.A.B'>" |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: