Skip to content

Support field in dataclass member initialization #2280

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

Merged
merged 2 commits into from
Aug 17, 2023

Conversation

ubaidsk
Copy link
Collaborator

@ubaidsk ubaidsk commented Aug 16, 2023

towards #2276

@ubaidsk ubaidsk marked this pull request as draft August 16, 2023 23:38
@ubaidsk ubaidsk force-pushed the support_field_in_dataclass_mem_init branch from 4a10c8b to 9bdb90e Compare August 16, 2023 23:40
@ubaidsk ubaidsk marked this pull request as ready for review August 16, 2023 23:45
@ubaidsk ubaidsk requested a review from certik August 16, 2023 23:50
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good.

b: bool = True
c: list[i32] = field(default_factory=lambda: [1, 2, 3])
d: i32[3] = field(default_factory=lambda: array([4, 5, 6]))
e: i32 = field(default=-5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as:

Suggested change
e: i32 = field(default=-5)
e: i32 = -5

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think they are equivalent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are equivalent, then I would almost not support the duplicate way of doing it ("just one way of doing things").

@ubaidsk ubaidsk merged commit b70bfdf into lcompilers:main Aug 17, 2023
@ubaidsk ubaidsk deleted the support_field_in_dataclass_mem_init branch August 17, 2023 06:05
@ubaidsk ubaidsk restored the support_field_in_dataclass_mem_init branch August 17, 2023 06:06
@ubaidsk ubaidsk deleted the support_field_in_dataclass_mem_init branch August 17, 2023 06:07
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

Successfully merging this pull request may close these issues.

2 participants