Message358611
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)
True
* 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)
Namespace(abc=10)
>>> SimpleNamespace(abc=10)
namespace(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)' 'args.abc'
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)' 'args.abc'
10000000 loops, best of 11: 32.4 nsec per loop |
|
Date |
User |
Action |
Args |
2019-12-18 05:42:15 | rhettinger | set | recipients:
+ rhettinger, eric.snow, paul.j3 |
2019-12-18 05:42:15 | rhettinger | set | messageid: <1576647735.64.0.921659793768.issue39076@roundup.psfhosted.org> |
2019-12-18 05:42:15 | rhettinger | link | issue39076 messages |
2019-12-18 05:42:15 | rhettinger | create | |
|