Browse Source

added __contains__ and __getitem__ implementations to generated python code for _hx_AnonObject, so it is subscriptable and behaves like a python dict (#9119)

closes #9109
Jesse Rosalia 5 years ago
parent
commit
67476abe10
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/generators/genpy.ml

+ 4 - 0
src/generators/genpy.ml

@@ -2434,6 +2434,10 @@ module Generator = struct
 				spr ctx "        self.__dict__ = fields\n";
 				spr ctx "    def __repr__(self):\n";
 				spr ctx "        return repr(self.__dict__)\n";
+				spr ctx "    def __contains__(self, item):\n";
+				spr ctx "        return item in self.__dict__\n";
+				spr ctx "    def __getitem__(self, item):\n";
+				spr ctx "        return self.__dict__[item]\n";
 				spr ctx "    def __getattr__(self, name):\n";
 				spr ctx "        if (self._hx_disable_getattr):\n";
 				spr ctx "            raise AttributeError('field does not exist')\n";