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

Unexpected default value for dict as class param #15

Open
patarapolw opened this issue Jun 28, 2019 · 0 comments
Open

Unexpected default value for dict as class param #15

patarapolw opened this issue Jun 28, 2019 · 0 comments

Comments

@patarapolw
Copy link

patarapolw commented Jun 28, 2019

class IParserResult(EasyDict):
    cond: dict
    is_: set
    sortBy: str = "deck"
    desc: bool = False

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.is_ = set()


print(IParserResult(cond=dict()))

Gets {'cond': {'sortBy': 'deck', 'desc': False, 'is_': set()}, 'sortBy': 'deck', 'desc': False, 'is_': set()}

But,

@dc.dataclass
class IParserResult:
    cond: dict
    is_: set = dc.field(default_factory=set)
    sortBy: str = "deck"
    desc: bool = False


print(IParserResult(cond=dict()))

Gets IParserResult(cond={}, is_=set(), sortBy='deck', desc=False), with no recursion, at should be expected.

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