disallow_empty, disallow_unknown, and None values #178
Unanswered
topherbuckley
asked this question in
Q&A
Replies: 1 comment 7 replies
-
Regarding
Thanks for digging through this code and finding bugs. As for the other question on optional vs required, the easy way to tell if a parameter is optional or required is just to look at the signature of the constructor: if a parameter has However I think I am missing some context: can you elaborate on why you need optional/required information in your PR and how you plan to use it? |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Can someone help me understand the intent behind
disallow_empty
? I thought I understood, that it would check if if somevalue
hadlen(value)==0
as per here but I'm quite confused by things likefrom here
It would seem the check for whether something was
len(value)==0
will never be checked because the above statement will returnNone
instead of error out whenvalue==None
. I would have thoughtNone
is also "empty", but it seems this is interpreted differently here.The main reason I ask is because I was trying to interpret the "required" and "optional" parameters to each of the In/Out/Intra transactions listed in the config readme with regards to these
disallow_empty
anddisallow_unknown
. Generally speaking it seems thatdisallow_unknown
appears to be of no consequence to being "required" or "optional", whereas anything that isdisallow_empty
would be required, and anything that is allowed to be empty, is optional. The only outlier there is thefiat_ticker
which appears to be "optional" due to the fact that this value is filled in with the native fiat in a few places in the transaction_resolverThis seems very opaque to me, since here
It is
disallow_empty
, so I would think that aNone
value would fail. These validate methods appear to let theseNone
values through, and some are handled by transaction_resolver.So in the end, I am planning to just add my own field specifying
is_required
in some AbstractTransactionItem class to help clear these things up, but if there is a way to determine if something is required or not just by the values ofdisallow_empty
anddisallow_unknown
please let me know.Looking at it all again, I guess the easiest way for me to determine if something is required or optional is to just look at the method call where it is verified (e.g. _validate_optional_string_field vs _validate_string_field). Is there a reason it was implemented this way? In other words, I'm curious if it doesn't make more things more clear to have a third
bool
calledrequired
in all of the constructors for things extending AbstractTransaction, and then just have one unified validate method for strings. I guess you lose some type hinting for the return value then. Anyways, I think I can add some clarity on this after getting my AbstractTransactionItem class finished.Beta Was this translation helpful? Give feedback.
All reactions