Skip to content

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

Closed
westurner wants to merge 1 commit intoipython:masterfrom
westurner:ENH_ipstruct.Struct_OrderedDict
Closed

ENH,PRF: ipstruct.py: class Struct(collections.OrderedDict or dict)#4
westurner wants to merge 1 commit intoipython:masterfrom
westurner:ENH_ipstruct.Struct_OrderedDict

Conversation

@westurner
Copy link
Copy Markdown

  • cross-link w/ nbformat changes, ipython/jupyter version requirements & changelog

@westurner
Copy link
Copy Markdown
Author

  • PLS ("please test")
    • TODO: enqueue a Travis build of notebook

@westurner
Copy link
Copy Markdown
Author

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

@minrk
Copy link
Copy Markdown
Member

minrk commented Dec 13, 2015

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
Copy link
Copy Markdown
Author

No functionality should be added to this repository

I did read that.

I thought/think this solution is justifiable because:

  • c "structs" are Ordered sets of keys/values.
  • I have no idea what the downstream (ENH: v4/nbjson.py: json.loads(object_pairs_hook=collections.OrderedDict) jupyter/nbformat#30 interface is for nbformat.notebooknode.NotebookNode(ipython_genutils.ipstruct.Struct).
    • Would OrderedDefaultDict suffice?
    • Should there be an IStruct / INotebookNode for documentation purposes?
      • I suppose I could just run the whole [notebook, ] test grid, but a dev might have more back-history in re: what parts of Struct NotebookNode must now reimplement?

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
Copy link
Copy Markdown
Author

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

@westurner
Copy link
Copy Markdown
Author

See jupyter/nbformat#30 for a discussion about:

  • PYTHONHASHSEED and dict.__repr__ / collections.OrderedDict.__repr__ and [doc]tests

@takluyver
Copy link
Copy Markdown
Member

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 ;-)

@takluyver takluyver closed this Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants