瀏覽代碼

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 年之前
父節點
當前提交
67476abe10
共有 1 個文件被更改,包括 4 次插入0 次删除
  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 "        self.__dict__ = fields\n";
 				spr ctx "    def __repr__(self):\n";
 				spr ctx "    def __repr__(self):\n";
 				spr ctx "        return repr(self.__dict__)\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 "    def __getattr__(self, name):\n";
 				spr ctx "        if (self._hx_disable_getattr):\n";
 				spr ctx "        if (self._hx_disable_getattr):\n";
 				spr ctx "            raise AttributeError('field does not exist')\n";
 				spr ctx "            raise AttributeError('field does not exist')\n";