Author rhettinger
Recipients eric.snow, paul.j3, rhettinger
Date 2019-12-18.05:42:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
There are some sticking points:

* types.SimpleNamespace() sorts attributes, so this would get in the way of issue #39058.

* argparse.Namespace() supports a __contains__() method that isn't offered by types.SimpleNamespace():

    >>> 'abc' in Namespace(abc=10)

* Argparse is sensitive to start-up time so we mostly want to avoid adding new dependencies.  Start-up time recently got worse when the re module added a number of dependencies.

* The __repr__ for SimpleNamespace() doesn't round-trip and isn't what we have now with Namespace.  That potentially breaks doctests and diverges from published examples:

    >>> Namespace(abc=10)
    >>> SimpleNamespace(abc=10)

* Ironically, the class name "Namespace" is simpler than "SimpleNamespace" ;-)

* Much of the code in argparse.Namespace() inherits from _AttributeHolder, so switching to types.SimpleNamespace() doesn't really save us much code.

Are there any upsides to switching?  Attribute lookup is almost equally fast using either approach, so there is no speed benefit:

    $ python3.8 -m timeit -r 11 -s 'from argparse import Namespace as NS' -s 'args=NS(abc=10)' ''
    10000000 loops, best of 11: 32.7 nsec per loop

    $ python3.8 -m timeit -r 11 -s 'from types import SimpleNamespace as NS' -s 'args=NS(abc=10)' ''
    10000000 loops, best of 11: 32.4 nsec per loop
Date User Action Args
2019-12-18 05:42:15rhettingersetrecipients: + rhettinger, eric.snow, paul.j3
2019-12-18 05:42:15rhettingersetmessageid: <>
2019-12-18 05:42:15rhettingerlinkissue39076 messages
2019-12-18 05:42:15rhettingercreate