-
Notifications
You must be signed in to change notification settings - Fork 0
Define typed struct fields with context managers #76
base: master
Are you sure you want to change the base?
Conversation
@koreno, @doroncohen - I need your opinion. I'm going to need to add some configuration fields on the fields, to allow customizing some of
Now, regarding the new syntax - I'm pondering how to approach it:
|
About your second question I would go with the 2nd approach it is much clearer for this scenario. if you needed to set an alternative |
How do you feel about this syntax? class Foo(TypedStruct):
a = int; DEFAULT(5)
b = float; CONVERTIBLE_FROM(int, str)
# Or, if there are many fields to set:
c = str
DEFAULT(20)
CONVERTIBLE_FROM(int, str)
VALIDATION(lambda s: 2 <= len(s)) |
|
I can bare with the semicolon syntax although I don't think linters like the use of it. second option is not optimal, maybe use indentation in some way like:
you may have to use a tuple for that |
If I used a tuple, completion would no longer work. That was also the problem with using |
The magic here is so strong you can start calling me "Idandalf the White", but this will allow much more elegant definition of typed structs.
For example, we have something like this in our mayhem configuration:
With this new feature, we could make it look like this: