8000 No "post-init only" marker · Issue #57 · biqqles/dataclassy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
No "post-init only" marker #57
Open
@AJR1991

Description

@AJR1991

I want to use slots in CPython using dataclassy, but I also want to be able to hide initializers for certain variables from the user. For example:

@dataclass(slots=True)
class TestDataClass:
    normal: float
    _hidden: str = post_init("Test") 
    _post: float = post_init()

    def __post_init__(self):
        self._post = 3.141 * self.normal * self.normal

What I'm doing here is making _hidden and _post unable to be initialized as part of the given args on construction (meaning you can't set it via _hidden="hello") . It's possible to do this kind of thing without slots by just initializing it in __post_init__ but with slots, you can't without having to define __slots__ at the top, which looks ugly.

Is it possible to add this functionality? Or am I misreading documentation and this is already possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0