PFython / cleverdict

A JSON-friendly data structure which allows both object attributes and dictionary keys and values to be used simultaneously and interchangeably.
MIT License
101 stars 9 forks source link

More elegant solution for CleverDict.ignore #23

Open PFython opened 3 years ago

PFython commented 3 years ago

Currently it's possible to set dictionary items with the same (key) names as existing methods e.g.

x=CleverDict() x['save']="What a great save!" x['save'] 'What a great save!'

They don't overwrite the existing method (a good thing!) but there is some potentially confusing behaviour:

x CleverDict({}, _aliases={}, _vars={})

This is because CleverDict.ignore includes {'save_path', 'delete', 'save', '_aliases'}.

Furthermore, although a user is unlikely to import their own data with an existing key of "_aliases", the other three ignored attributes might quite plausibly feature. In this case the solution is just to rename the keys before importing to CleverDict but the danger is that a user might not even know/expect this to be an issue until it becomes one...

FelixTheC commented 2 years ago

I think you can close this or??