nickstanisha / nesteddict

A nested dictionary data structure for Python
MIT License
0 stars 0 forks source link

Consider removing dict baseclass #5

Open nickstanisha opened 7 years ago

nickstanisha commented 7 years ago

Because of NestedDict's behavior when indexing tuples, the following situation could arise for a user of this project

def my_user_function(dictobject):
    assert(isinstance(dictobject, dict)), "I'm a function that only works on dicts"
    # start indexing tuples into dictobject
    return dictobject

dictobject == nesteddictobject  # True
my_user_function(dictobject) == my_user_function(nesteddictobject)  # False

In response to this dilemma, I could either

Using approach 2, the following conditions would have to be satisfied 1) isinstance(obj, dict) == False 2) Attributes not found in NestedDict will default to attributes in the internal self._dict (effectively replicating the current class inheritance)

nickstanisha commented 7 years ago

@meowklaski Feel free to develop and make pull requests against the no_inheritance branch. I've already added the minimum level of functionality to pass all of the tests, but I'm not satisfied with it yet because it doesn't fully satisfy point 2 above.

Once the no_inheritance branch is ready, I'll do a final assessment of whether or not the additional code complexity is worth avoiding the headache in the code sample above.