소스 검색

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 "    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";