Author eric.snow
Recipients eric.snow, paul.j3, rhettinger
Date 2019-12-27.20:06:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CALFfu7CYt-xTy1us1BGCnD6s-jB37zGyFbWjaYpHCSOj2QrzcA@mail.gmail.com>
In-reply-to <1576647735.64.0.921659793768.issue39076@roundup.psfhosted.org>
Content
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.
History
Date User Action Args
2019-12-27 20:06:13eric.snowsetrecipients: + eric.snow, rhettinger, paul.j3
2019-12-27 20:06:13eric.snowlinkissue39076 messages
2019-12-27 20:06:12eric.snowcreate