Replies: 1 comment 4 replies
-
We override init for one main reason: ensure the created object is valid. Not using init as the primary means of construction wouldn't be very pythonic. Secondly, I think to achieve what you suggest we'd also have to leave repr untouched, which we override often to produce easier to read prints, with reduced verbosity. This is especially useful for types. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It is really nice (especially for debugging) to be able to reconstruct a Python object by directly evaluating its string
__repr__()
. If dataclasses are used "all the way down" then this is possible as long as the generated__init__()
and__repr__()
methods are preserved. However in hugr-py many of the__init__()
methods are overridden; so for example if I have aHugr
h
:I wonder if we could replace the overriding
__init__()
methods with classmethods that do the same job.Beta Was this translation helpful? Give feedback.
All reactions