text: # To use this code, make sure you
  #
  #     import json
  #
  # and then, to convert JSON from a string, do
  #
  #     result = users_set_photo_response_from_dict(json.loads(json_string))
  
  from dataclasses import dataclass
  from typing import Optional, Any, TypeVar, Type, cast
  
  
  T = TypeVar("T")
  
  
  def from_str(x: Any) -> str:
      assert isinstance(x, str)
      return x
  
  
  def from_none(x: Any) -> Any:
      assert x is None
      return x
  
  
  def from_union(fs, x):
      for f in fs:
          try:
              return f(x)
          except:
              pass
      assert False
  
  
  def from_bool(x: Any) -> bool:
      assert isinstance(x, bool)
      return x
  
  
  def to_class(c: Type[T], x: Any) -> dict:
      assert isinstance(x, c)
      return cast(Any, x).to_dict()
  
  
  @dataclass
  class Profile:
      image_24: Optional[str] = None
      image_32: Optional[str] = None
      image_48: Optional[str] = None
      image_72: Optional[str] = None
      image_192: Optional[str] = None
      image_512: Optional[str] = None
      image_1024: Optional[str] = None
      image_original: Optional[str] = None
      avatar_hash: Optional[str] = None
  
      @staticmethod
      def from_dict(obj: Any) -> 'Profile':
          assert isinstance(obj, dict)
          image_24 = from_union([from_str, from_none], obj.get("image_24"))
          image_32 = from_union([from_str, from_none], obj.get("image_32"))
          image_48 = from_union([from_str, from_none], obj.get("image_48"))
          image_72 = from_union([from_str, from_none], obj.get("image_72"))
          image_192 = from_union([from_str, from_none], obj.get("image_192"))
          image_512 = from_union([from_str, from_none], obj.get("image_512"))
          image_1024 = from_union([from_str, from_none], obj.get("image_1024"))
          image_original = from_union([from_str, from_none], obj.get("image_original"))
          avatar_hash = from_union([from_str, from_none], obj.get("avatar_hash"))
          return Profile(image_24, image_32, image_48, image_72, image_192, image_512, image_1024, image_original, avatar_hash)
  
      def to_dict(self) -> dict:
          result: dict = {}
          result["image_24"] = from_union([from_str, from_none], self.image_24)
          result["image_32"] = from_union([from_str, from_none], self.image_32)
          result["image_48"] = from_union([from_str, from_none], self.image_48)
          result["image_72"] = from_union([from_str, from_none], self.image_72)
          result["image_192"] = from_union([from_str, from_none], self.image_192)
          result["image_512"] = from_union([from_str, from_none], self.image_512)
          result["image_1024"] = from_union([from_str, from_none], self.image_1024)
          result["image_original"] = from_union([from_str, from_none], self.image_original)
          result["avatar_hash"] = from_union([from_str, from_none], self.avatar_hash)
          return result
  
  
  @dataclass
  class UsersSetPhotoResponse:
      ok: Optional[bool] = None
      profile: Optional[Profile] = None
      error: Optional[str] = None
      needed: Optional[str] = None
      provided: Optional[str] = None
  
      @staticmethod
      def from_dict(obj: Any) -> 'UsersSetPhotoResponse':
          assert isinstance(obj, dict)
          ok = from_union([from_bool, from_none], obj.get("ok"))
          profile = from_union([Profile.from_dict, from_none], obj.get("profile"))
          error = from_union([from_str, from_none], obj.get("error"))
          needed = from_union([from_str, from_none], obj.get("needed"))
          provided = from_union([from_str, from_none], obj.get("provided"))
          return UsersSetPhotoResponse(ok, profile, error, needed, provided)
  
      def to_dict(self) -> dict:
          result: dict = {}
          result["ok"] = from_union([from_bool, from_none], self.ok)
          result["profile"] = from_union([lambda x: to_class(Profile, x), from_none], self.profile)
          result["error"] = from_union([from_str, from_none], self.error)
          result["needed"] = from_union([from_str, from_none], self.needed)
          result["provided"] = from_union([from_str, from_none], self.provided)
          return result
  
  
  def users_set_photo_response_from_dict(s: Any) -> UsersSetPhotoResponse:
      return UsersSetPhotoResponse.from_dict(s)
  
  
  def users_set_photo_response_to_dict(x: UsersSetPhotoResponse) -> Any:
      return to_class(UsersSetPhotoResponse, x)
  