Finistere/antidote

Constants doesn't work with a dataclass

Closed this issue · 1 comments

This works as a plain-old-class:

class Config(Constants):
    """Global settings for this app."""
    PUNCTUATION: str = const("!")

Making this as a dataclass:

@dataclass
class Config(Constants):
    """Global settings for this app."""
    PUNCTUATION: str = const("!")

...leaves the value, when injected, as a LazyConst.

It does work with @dataclass, but you need to tell to @dataclass to leave PUNCTUATION alone with ClassVar:

from dataclasses import dataclass
from typing import ClassVar

from antidote import const, Constants, world


@dataclass
class Config(Constants):
    """Global settings for this app."""
    PUNCTUATION: ClassVar[str] = const("!")


assert world.get(Config.PUNCTUATION) == "!"
assert Config().PUNCTUATION == "!"