Make Node a dataclass #5

Open
adsharma wants to merge 1 commit from adsharma/dataclass into main
adsharma commented 2021-03-31 19:29:39 +00:00 (Migrated from github.com)

Dataclasses make the code more compact and generate many convenience
functions.

Dataclasses make the code more compact and generate many convenience functions.
adsharma (Migrated from github.com) reviewed 2021-03-31 19:30:41 +00:00
adsharma (Migrated from github.com) commented 2021-03-31 19:30:41 +00:00

This code would not be necessary if we made:

read_capacity: float = 1.0

in the dataclass. More instances below.

This code would not be necessary if we made: ``` read_capacity: float = 1.0 ``` in the dataclass. More instances below.
mwhittaker commented 2021-04-05 17:01:52 +00:00 (Migrated from github.com)

Ah, I've been targeting Python 3.6, and I think dataclasses are a 3.7+ thing?

Ah, I've been targeting Python 3.6, and I think dataclasses are a 3.7+ thing?
adsharma commented 2021-04-05 18:45:00 +00:00 (Migrated from github.com)

Backports are available: https://pypi.org/project/dataclasses/

In general, dataclasses eliminate so much boilerplate code that I use them wherever I can.

Backports are available: https://pypi.org/project/dataclasses/ In general, dataclasses eliminate so much boilerplate code that I use them wherever I can.
mwhittaker (Migrated from github.com) reviewed 2021-04-11 01:42:53 +00:00
mwhittaker (Migrated from github.com) left a comment

Thanks for the PR! I spent some time reading up on dataclasses, and I think the switch here may not be worth it.

  • I don't think we benefit much since there's not a lot of boilerplate to remove in this case.
  • The dataclass also introduces capacity into Node which it didn't previously have, and it's not clear what capacity means. For example, if we construct a node like Node('a', read_capacity=100, write_capacity=200), there's not a nice value for capacity.
  • Also since Node is part of the Expr hierarchy, it feels weird to me that Node would be a dataclass but not And or Or.
Thanks for the PR! I spent some time reading up on dataclasses, and I think the switch here may not be worth it. - I don't think we benefit much since there's not a lot of boilerplate to remove in this case. - The dataclass also introduces `capacity` into `Node` which it didn't previously have, and it's not clear what `capacity` means. For example, if we construct a node like `Node('a', read_capacity=100, write_capacity=200)`, there's not a nice value for `capacity`. - Also since `Node` is part of the `Expr` hierarchy, it feels weird to me that `Node` would be a dataclass but not `And` or `Or`.
mwhittaker (Migrated from github.com) commented 2021-04-11 01:34:58 +00:00

This should be __post_init__.

This should be `__post_init__`.
adsharma commented 2021-04-12 20:54:52 +00:00 (Migrated from github.com)

Yes - it saves only 10 lines in this diff. Not an earth shattering difference :)

I've addressed the bugs you found in the code and simplified the typing and default values.

I'll leave it here just in case you end up using dataclasses elsewhere and then want to convert this one for consistency.

Yes - it saves only 10 lines in this diff. Not an earth shattering difference :) I've addressed the bugs you found in the code and simplified the typing and default values. I'll leave it here just in case you end up using dataclasses elsewhere and then want to convert this one for consistency.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin adsharma/dataclass:adsharma/dataclass
git checkout adsharma/dataclass

Merge

Merge the changes and update on Forgejo.
git checkout main
git merge --no-ff adsharma/dataclass
git checkout main
git merge --ff-only adsharma/dataclass
git checkout adsharma/dataclass
git rebase main
git checkout main
git merge --no-ff adsharma/dataclass
git checkout main
git merge --squash adsharma/dataclass
git checkout main
git merge --ff-only adsharma/dataclass
git checkout main
git merge adsharma/dataclass
git push origin main
Sign in to join this conversation.
No description provided.