from dataclasses import dataclass
from enum import Enum
from typing import List
import mew
class Type(Enum):
normal = 'normal'
electric = 'electric'
fire = 'fire'
fighting = 'fighting'
water = 'water'
psychic = 'psychic'
@mew.serializable
@dataclass
class Pokemon:
name: str
pokedex: int
type: Type
abilities: List[str]
>>> pikachu = Pokemon('Pikachu', 25, Type.electric, ['static', 'lightning rod'])
>>> pikachu
Pokemon(name='Pikachu', pokedex=25, type=<Type.electric: 'electric'>, abilities=['static', 'lightning rod'])
>>> pikachu.dumps()
'{"name": "Pikachu", "pokedex": 25, "type": "electric", "abilities": ["static", "lightning rod"]}'
>>> assert pikachu == Pokemon.loads(pikachu.dumps())
-
Notifications
You must be signed in to change notification settings - Fork 0
cliffxuan/mew
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Mew: python dataclass serializer/deserializer 🐱
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published