[Python-ideas] Anonymous namedtuples
Eric Snow
ericsnowcurrently at gmail.com
Tue Apr 19 20:26:42 EDT 2016
More information about the Python-ideas mailing list
Tue Apr 19 20:26:42 EDT 2016
- Previous message (by thread): [Python-ideas] Anonymous namedtuples
- Next message (by thread): [Python-ideas] Anonymous namedtuples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Apr 19, 2016 at 8:39 AM, Paul Moore <p.f.moore at gmail.com> wrote: > Having done some digging just now... SimpleNamespace is basically just > exposing for end users, the type that is used to build the > sys.implementation object. The definition is *literally* nothing more > than > > SimpleNamespace = type(sys.implementation) FYI, sys.implementation was added for PEP 421 (May-ish 2012). That PEP has a small section on the type I used. [1] At first it was unclear if I should even expose type(sys.implementation). [2] Nick suggested types.SimpleNamespace, so I went with that. [3] :) Note that the type is super simple/trivial, a basic subclass of object with a **kwargs __init__() to pre-populate and a nice repr. Both that first link [1] and the docs [4] spell it out. The point is that there isn't much to the type. It's a convenience, nothing else. I used to get roughly the same thing with "class SimpleNamespace: pass". :) FWIW, I proposed giving SimpleNamespace more exposure around the same time as PEP 421, and the reaction was lukewarm. [5] However, since then it's been used in several other places in the stdlib and I know of a few folks that have used it in their own projects. Regardless, ultimately the only reason I added it to the stdlib in the first place [6] was because it's the type of sys.implementation and it made more sense to expose it explicitly in the types module than implicitly via type(sys.implementation). -eric [1] https://www.python.org/dev/peps/pep-0421/#type-considerations [2] https://mail.python.org/pipermail/python-dev/2012-May/119771.html [3] https://mail.python.org/pipermail/python-dev/2012-May/119775.html [4] https://docs.python.org/3/library/types.html#types.SimpleNamespace [5] https://mail.python.org/pipermail/python-ideas/2012-May/015208.html [6] in contrast to argparse.Namespace and multiprocessing.managers.Namespace...
- Previous message (by thread): [Python-ideas] Anonymous namedtuples
- Next message (by thread): [Python-ideas] Anonymous namedtuples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list