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

reading of Config code is a bit unintuitive #1

Open
epogrebnyak opened this issue Jun 23, 2022 · 2 comments
Open

reading of Config code is a bit unintuitive #1

epogrebnyak opened this issue Jun 23, 2022 · 2 comments

Comments

@epogrebnyak
Copy link

epogrebnyak commented Jun 23, 2022

from lamya.config import Config as DefaultConfig
from lamya.site_generator import SiteGenerator

class Config(DefaultConfig):
    name = "dontpanic"
    url = "https://dont.panic"
    subtitle="we demand rigidly defined areas of doubt and uncertainty",
    content_directory="content",
    theme_options = {
        "sidebar": True,
        "sidebar_image": "/img/sidebar.png"
    }

site_gen = SiteGenerator.run_from_config(Config(), render=False)```

Maybe consider less inheriting:

DEFAULT_CONFIG = Config(
    name = "dontpanic"
    url = "https://dont.panic"
    subtitle="we demand rigidly defined areas of doubt and uncertainty",
    content_directory="content",
    theme_options = {
        "sidebar": True,
        "sidebar_image": "/img/sidebar.png"
    }

site_gen = SiteGenerator.run_from_config(DEFAULT_CONFIG, render=False)
@epogrebnyak
Copy link
Author

Having looked at https://github.com/vshotarov/lamya/blob/master/lamya/config.py it seems inherting is really a design decision in lamya. However, to me it looks like making Config simply a dataclass is a much clear path.

@vshotarov
Copy link
Owner

Oh, thanks a lot for bringing this up, I haven't seen the dataclasses before, but they look great! They remind me a lot of Haskell's data structures, which I really like and they seem very appropriate for a config class.

I've had a quick go at converting the Config class to use them, is this - 35a65fb - what you had in mind?

One thing I really don't like about dataclasses, though, is that they require type hints, which I am not a fan of. If I am to merge this in I am considering using one of the cheats in Dataclasses without type annotations.

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

2 participants