-
Notifications
You must be signed in to change notification settings - Fork 205
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
convert_value_type
checks has broken code
#4785
Comments
convert_value_type
checks for checksums has broken code
convert_value_type
checks for checksums has broken codeconvert_value_type
checks has broken code
We cannot use `isinstance` on non-trivial types, i.e. our tuple-specifications. Incidently it works if the result is the type in the first element of the tuple, otherwise it fails with a `TypeError` because the remainder is not a type. The correct way is to use our `is_value_of_type`. 2 small corrections: 1. We don't need `EASY_TYPES` which had some types missing, e.g. `float`. Instead we can check if a type was passed and hence can be used with `isinstance`. 2. `convert_value_type` shouldn't be called when the type is already correct. We ensure that in all usages in framework code. So issue a warning for that case. Fixes easybuilders#4785
AFAIK we haven't supported that for a long time, if at all. Can't find where the
As for:
It does work (somehow): For However you are right: The code is incomplete: We only support a single type for easyconfig params, no alternatives. And all our conversion functions are "correct enough". What happens:
So the wrong value doesn't matter for our current usages. However it still is wrong and I opened a PR to make this right. With this you can likely implement alternatives like:
Maybe this can be used from or combined with code from |
We cannot use `isinstance` on non-trivial types, i.e. our tuple-specifications. Incidently it works if the result is the type in the first element of the tuple, otherwise it fails with a `TypeError` because the remainder is not a type. The correct way is to use our `is_value_of_type`. 2 small corrections: 1. We don't need `EASY_TYPES` which had some types missing, e.g. `float`. Instead we can check if a type was passed and hence can be used with `isinstance`. 2. `convert_value_type` shouldn't be called when the type is already correct. We ensure that in all usages in framework code. So issue a warning for that case. Fixes easybuilders#4785
I guess I'm confused by
Hm, since that matches typ[0] it never checks typ[1]. If one needs to keep that piece of code around, it should probably be though i think the check:
is just overkill, as it really only tests the outermost type, of our own Also, just testing
the error you get is
yikes. The old behavior in EB 4 was much nicer
So I feel like there sure is a lot of very hard to follow code here, and we aren't getting the helpful very helpful error messages. |
We cannot use `isinstance` on non-trivial types, i.e. our tuple-specifications. Incidently it works if the result is the type in the first element of the tuple, otherwise it fails with a `TypeError` because the remainder is not a type. The correct way is to use our `is_value_of_type`. 2 small corrections: 1. We don't need `EASY_TYPES` which had some types missing, e.g. `float`. Instead we can check if a type was passed and hence can be used with `isinstance`. 2. `convert_value_type` shouldn't be called when the type is already correct. We ensure that in all usages in framework code. So issue a warning for that case. Fixes easybuilders#4785
The list
That doesn't cut it either:
True, we were in some cases just doing a partial transform and let the easyconfig handle the rest.
So maybe we really shouldn't to that much type checking on the result of the conversion functions or inside the conversion functions. But then we have to be sure to handle that in the easyconfig better. Additionally we could allow a "wildcard type": I had played with adding
That would still fail the type check unless we allow a "wildcard type" there. So no free lunch here too. |
I was going to see what it would take to allow checksums to be a plain top level dict, and it turns out it's very simple. The only code preventing this is this code
easybuild-framework/easybuild/framework/easyconfig/types.py
Lines 552 to 557 in 4702af0
which converts everything to a list (of just the keys).
First problem is that, while our documentation suggests that a simple single string is supported, this is not the case. Such a string would be converted to a list of single characters. This never worked as far as I can tell. I suppose this is good, because that's one pattern we can then just remove. It must always be a list.
Secondly, if one tries to modify
to_checksums
, to for exmaple allow a dict to be passed throughor similar, the code trips up over
easybuild-framework/easybuild/framework/easyconfig/types.py
Lines 252 to 253 in 4702af0
which is trying use
easybuild-framework/easybuild/framework/easyconfig/types.py
Lines 683 to 695 in 4702af0
which is defined here:
easybuild-framework/easybuild/framework/easyconfig/types.py
Lines 656 to 657 in 4702af0
but this is not a value input for
isinstance
, and the code crashes withclearly, this part of the code has never even worked. Shall we just go ahead and delete this extra unnecessary check?
I really only want to allow for checksum to a be a dict, and it almost seems from the code like it should be supported already by
CHECKSUM_DICT
viaCHECKABLE_TYPES
, but since the code always checks foris_value_of_type(val, typ)
anyway, wheretyp == list
then this means nothing. It's always going to be forcible converted to alist
no matter what, so it's pointless to add all of these toCHECKABLE_TYPES
?@Flamefire am I missing something here?
The text was updated successfully, but these errors were encountered: