WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

How to allow different config class assigned to the same argument #733

@thomassajot

Description

@thomassajot

Is it possible to define two different config objects which are build from two different classes?

Some pseudo code

class Player:
    def __init__(self, name: str): 
        self.name = name
    def move(self):
        print('Moving')


class Monster:
    def __init__(self, magic_type: str): 
        self.magic_type = magic_type
    def move(self):
        print('Moving')

def run_engine(entity):
    entity.move()

PlayerCfg = builds(Player)
MonsterCfg = builds(Monster)
main = builds(run_engine, entity=PlayerCfg('DummyPlayerDefault'))

Now assigning a MonsterCfg object to the main function will raise an error as MonsterCfg is not a child of PlayerCfg.
Is there a way to both assign a default value (here dummy player) and allow for different config class to be assigned?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions