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

Late-init fields still appear in __init__ #61

Open
robertodr opened this issue Mar 10, 2023 · 1 comment
Open

Late-init fields still appear in __init__ #61

robertodr opened this issue Mar 10, 2023 · 1 comment
Labels
question Further information is requested

Comments

@robertodr
Copy link

I'm comparing this package to the standard dataclasses.

In this case, the __init__ method will only accepts the wheels argument:

from dataclasses import dataclass, field


@dataclass(eq=False)
class Vehicle:

    wheels: int
    _wheels: int = field(init=False, repr=False)

However, the equivalent with dataclassy:

from dataclassy import dataclass


@dataclass(eq=False)
class Vehicle:
    wheels: int
    _wheels: int = None

will accept both wheels and _wheels as arguments. Is this intended?

@biqqles
Copy link
Owner

biqqles commented Mar 21, 2023

Yes, it's intended. Every annotation corresponds to an argument to __init__.

I checked the 'Differences' table and it isn't clear so I understand the confusion. (Setting a default to None is simply a way of avoiding having to pass it as an argument. I never considered that you might actually want to hide an argument, to be honest I'm still not sure I see the utility.)

A field without an annotation is not included in the arguments to __init__, but this means it acts like a class variable (is not copied upon instantiation) which is probably not what you want.

@biqqles biqqles added the question Further information is requested label Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants