ipython / ipython_genutils

Vestigial IPython utilities: DO NOT USE
Other
11 stars 22 forks source link

ENH,PRF: ipstruct.py: class Struct(collections.OrderedDict or dict) #4

Closed westurner closed 8 years ago

westurner commented 8 years ago
westurner commented 8 years ago
westurner commented 8 years ago

See also: https://github.com/jupyter/nbformat/pull/30 "ENH: v4/nbjson.py: json.loads(object_pairs_hook=collections.OrderedDict)"

minrk commented 8 years ago

From the README:

No functionality should be added to this repository

This package is an artifact of the Jupyter/IPython repo split, and we aren't planning to ever do another release of it, unless we find important bugs. Ultimately, we want to wean the other repos off of this one by shifting to standard utilities, such as six, etc. No new functionality should be added here. Any downstream changes that would rely on new features here should be implemented in the downstream repo instead of here.

westurner commented 8 years ago

No functionality should be added to this repository

I did read that.

I thought/think this solution is justifiable because:

From https://mail.python.org/pipermail/python-ideas/2015-November/037163.html :


    class OrderedDefaultDict(OrderedDict):
        def __init__(self, default_factory=None, *a, **kw):
            OrderedDict.__init__(self, *a, **kw)
            self.default_factory = default_factory
        def __missing__(self, key):
            self[key] = value = default_factory()
            return value
westurner commented 8 years ago

Instead of DictCls as an easily-documented in-code constant, this could be:

westurner commented 8 years ago

See https://github.com/jupyter/nbformat/pull/30 for a discussion about:

takluyver commented 8 years ago

Closing along with jupyter/nbformat#30.

'Struct' is possibly an unfortunate name. The class offers some features like Structs in other languages - primarily accessing items using a.foo attribute syntax - but it already does what we need, and we don't need it to be ordered. Naming things is hard ;-)