Eric Snow <ericsnowcurren...@gmail.com> added the comment:
Sorry if there was any confusion. I didn't mean to suggest we get rid of argparse.Namespace (in favor of SimpleNamespace). Rather, the former would subclass the latter. > * types.SimpleNamespace() sorts attributes, so this would get in the way of > issue #39058. hence issue 39075 > * argparse.Namespace() supports a __contains__() method that isn't offered by > types.SimpleNamespace(): As I suggested originally, there isn't any problem here if argparse.Namespace subclasses SimpleNamespace. > * Argparse is sensitive to start-up time so we mostly want to avoid adding > new dependencies. I agree on avoiding extra imports. The simple solution right now is to use "type(sys.implementation)", though that isn't the clearest code. FWIW, this would also be solved if we added SimpleNamespace to the builtins, but that is a separate discussion. :) > * The __repr__ for SimpleNamespace() doesn't round-trip and isn't what we > have now with Namespace. We could certainly fix the repr, but that's kind of irrelevant here if argparse.Namespace is a subclass. FWIW, this is also resolved if we add SimpleNamespace to the builtins (as "namespace"). > * Ironically, the class name "Namespace" is simpler than "SimpleNamespace" ;-) Agreed. :) We only used that long name because putting it in the "types" module mean it needed to have an extra clear name. That said, it is irrelevant here if argparse.Namespace is a subclass > * Much of the code in argparse.Namespace() inherits from _AttributeHolder, so > switching to types.SimpleNamespace() doesn't really save us much code. Honestly, _AttributeHolder isn't needed. The only thing it provides is a nice repr (like SimpleNamespace does), with some extra functionality for dynamically sorting/filtering down the attrs shown in the repr. There are 3 subclasses and Namespace doesn't even use the attr filtering. The implementation doesn't seem to warrant a dedicated base class and it would be simpler for those 2 subclasses to each to have a dedicated __repr__ implementation (and for Namespace to subclass SimpleNamespce), rather than to subclass _AttributeHolder. Subclassing from _AttributeHolder gives the illusion that there is something more going on there than there actually is. Aside from that, there's the weaker argument about consistency and avoiding duplication (i.e. SimpleNamespace is the canonical "simple" namespace implementation in Python). Also, if SimpleNamespace had existed when argparse was written then I expect it would have been used instead. > Are there any upsides to switching? Attribute lookup is almost equally fast > using either approach, so there is no speed benefit: Yeah, I didn't expect there to much difference in performance. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39076> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com