[issue16160] subclassing types.SimpleNamespace does not work
Roundup Robot added the comment: New changeset c5124145e79e by Eric Snow in branch '3.3': Close #16160: Subclass support now works for types.SimpleNamespace. Thanks to RDM for noticing. http://hg.python.org/cpython/rev/c5124145e79e New changeset 47b9732696eb by Eric Snow in branch 'default': merge for issue #16160: Subclass support now works for types.SimpleNamespace. http://hg.python.org/cpython/rev/47b9732696eb -- nosy: +python-dev resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
Eric Snow added the comment: Am I good to commit this? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
R. David Murray added the comment: Thanks. I don't have a need for those in my current application at the current time. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
Changes by Eric Snow ericsnowcurren...@gmail.com: Removed file: http://bugs.python.org/file27512/issue16160.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
Eric Snow added the comment: Here's an updated patch that addresses Éric's review comments. -- Added file: http://bugs.python.org/file27524/issue16160.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
Eric Snow added the comment: Yikes. I'll get a patch up tonight. -- assignee: - eric.snow ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
Eric Snow added the comment: Here's a patch that fixes subclass support. It was supposed to work in the first place. Guess I had tunnel vision at the time. The fix is essentially a copy of the code in dict_new() in Objects/dictobject.c. I left out the part about releasing GC if the type is not a subclass. Note: see #15022, #15004, and #15003 for other things SimpleNamespace is missing. I can get those done if it would be meaningful to you. -- keywords: +patch stage: needs patch - patch review Added file: http://bugs.python.org/file27512/issue16160.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
New submission from R. David Murray: Python 3.3.0+ (3.3:152d85b2da3a, Oct 6 2012, 13:17:54) [GCC 4.6.3] on linux Type help, copyright, credits or license for more information. from types import SimpleNamespace class Foo(SimpleNamespace): ... pass ... y = Foo(bar=8, foo=9) y namespace() It doesn't work to define an __init__ method, either, which is what I really wanted to do. (I was subclassing to get the nice repr). -- messages: 172355 nosy: eric.snow, r.david.murray priority: normal severity: normal stage: needs patch status: open title: subclassing types.SimpleNamespace does not work type: behavior versions: Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16160] subclassing types.SimpleNamespace does not work
Christian Heimes added the comment: I have verified that the __init__ function isn't executed when SimpleNamespace is subclasses. I guess that's happening: http://docs.python.org/py3k/c-api/typeobj.html?highlight=tp_init#PyTypeObject.tp_init If the tp_new function returns an instance of some other type that is not a subtype of the original type, no tp_init function is called; if tp_new returns an instance of a subtype of the original type, the subtype’s tp_init is called. namespace_new always returns a namespace object no matter what. As namespace is not a subclass of the Foo (the other way around), the type check in type_call() fails and __init__ isn't called. The tp_new method needs a fix. That looks all wrong to me: import types class SubNS(types.SimpleNamespace): ... pass ... SubNS.__new__(SubNS) namespace() That's about right: class SubStr(str): ... pass ... type(SubStr.__new__(SubStr)) class '__main__.SubStr' -- nosy: +christian.heimes ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16160 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com