Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thomassajot opened this issue Sep 25, 2024 · 0 comments
Open

Comments

@thomassajot
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant