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

Can we override how {...} is interpretted? #8

Closed PFython closed 4 years ago

PFython commented 4 years ago

Is it possible/desirable to override curly brackets e.g.

from cleverdict import CleverDict x = {"a": "First letter"}

... would result in x being a CleverDict object not a regular dict?

salabim commented 4 years ago

No is the short answer.

PFython commented 4 years ago

before you think of changing the language semantics - think about the principle 'Explicit is better than implicit' - if you try to override '{}' or hide to avoid having to type 'OrderedDict' - you will end up making your code far more difficult to read for others - of for yourself 6 months down the line. Just type 'OrderedDict' - it is understood, and does what you want - more typing, but improved readability. – Tony Suffolk