|
|
|
|
|
by mazatta
3335 days ago
|
|
I've worked on codebases that use a similar thing, and I have yet to see one where this wasn't a mistake. Most of the time, this probably gives you exactly what you want, but then there are times where you discover bugs in production because data you assumed is your custom class is a plain old dict, and now you're raising AttributeError all over the place. Another wart is if you are unfortunate enough to have keys that match the name of one of dict's methods, then you have to resort to instance['items'], which defeats the purpose of using this in the first place. This is a fun trick, but if someone one my team tried to introduce this, it won't make it through code review. |
|