-
Notifications
You must be signed in to change notification settings - Fork 28
fix: preserve the order of elements of the list extract from defaults.ini #660
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
Conversation
36667fd
to
4823341
Compare
I have a question: why did we have this de-duplicating logic in the first place, and if we remove it does it break any of the current behaviors (i.e. those that may not be verified in any unit tests)? |
That's useful when the user makes a mistake in the configuration file while we expect to have unique values. We shouldn't remove this feature. |
Hmm interesting, I wonder what would be the examples in Macaron where the caller of
|
I'm not sure I agree. Checking for duplicates as a way to catch mistakes in the configuration can be the default and be done in one place. There is no point to repeat that outside the function call. I would argue that if a config needs to allow duplicates, that's a specific case and should be turned on explicitly. In general, I prefer to be as explicit as possible. So, I suggest to add a new argument to preserve the order, like |
My suggestion: I think that we should always keep the order (which is a sensible default behavior while there is no good reason to not keep the order), while optionally allowing for duplication. The logic would be different from the original one. I am thinking something similar to this (which is probably similar to what Behnaz is suggesting): # content is the list of values read from the config and split apart with the delimiter
# Therefore, content retains the initial order.
if duplication_allowed:
return content
else:
values = []
for item in content:
if item in values:
continue
values.append(item)
return values A dedicated set, for example |
I think I agree with most of what @nathanwn suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the fix.
…ments back to get_list
…ini (#660) Signed-off-by: Trong Nhan Mai <[email protected]>
…ini (#660) Signed-off-by: Trong Nhan Mai <[email protected]>
This PR is created to addressed to issue mentioned here #641 (comment).
This issue is addressed by removing the parameter
duplicate_ok
in theget_list
methodmacaron/src/macaron/config/defaults.py
Lines 18 to 26 in 023e095
get_list
method not modifying the order of elements in the return list of strings.As a result, the unit tests in tests/config/test_defaults.py are also re-implemented to reflect this new behavior, hence a major modification within that file.
In additions, I have also rename the parameter
item
tooption
according to the documentation of ConfigParser - https://docs.python.org/3/library/configparser.html#module-configparser