veekun / pokedex

more than you ever wanted to know about Pokémon
MIT License
1.44k stars 637 forks source link

Make Translation Tables Actual Classes #246

Open thechief389 opened 6 years ago

thechief389 commented 6 years ago

Currently, the translation tables e.g pokemon_names monkey-patch the created tables to poked.db.multilang. This can cause a lot of problems. i.e. if someone were to pickle an instance, this will happen

_pickle.PicklingError: Can't pickle <class 'pokedex.db.multilang.type_names'>: attribute lookup type_names on pokedex.db.multilang failed

It would be more efficient if the tables for translations were built-in to the module that creates the schema.

An example would be:


pokemon_species = create_translation_table(
    'pokemon_species_names',
    PokemonSpecies, 'names',
    relation_lazy='joined',
    name = Column(
        Text,
        nullable=True,
        index=True,
        doc=u"The name",
        info=dict(format='plaintext', official=True, ripped=True)),
    genus = Column(
        Text,
        nullable=True,
        doc=u'The short flavor text, such as "Seed" or "Lizard"; usually affixed with the word "Pokémon"',
        info=dict(official=True, format='plaintext')),
)
magical commented 6 years ago

What. Why are you trying to pickle a database object?

thechief389 commented 6 years ago

I'm making a text based rpg and I want to serialize an Pokemon that the player can use