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
Fix config.get for iterable sections #2020
Conversation
@@ -615,7 +615,11 @@ def get( | |||
self, val: str, section: Union[str, Iterable[str]] = "core", default: Any = None | |||
): | |||
"""Get a particular value from the config.""" | |||
return self._configs[section].get(val, default) |
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.
would only work for if session a str
@@ -615,7 +615,11 @@ def get( | |||
self, val: str, section: Union[str, Iterable[str]] = "core", default: Any = None | |||
): | |||
"""Get a particular value from the config.""" | |||
return self._configs[section].get(val, default) | |||
section_dict = self.get_section(section) |
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.
handles nested config sections
if section_dict is None: | ||
return default |
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.
returns default if the section doesn't exist. Could alternatively raise a KeyError if preferred. Fine either way
Codecov Report
@@ Coverage Diff @@
## main #2020 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 148 148
Lines 10381 10384 +3
=========================================
+ Hits 10381 10384 +3
Continue to review full report at Codecov.
|
@barrywhart could you take a look at this please, it's a quick bugfix for the config.get method |
Brief summary of the change made
Was using config.get method and realised it should take an iterable of str to handle nested config sections but the current implementation only works for a single section str.
Used the already existing get_sections method to handle this.
Are there any other side effects of this change that we should be aware of?
No
Pull Request checklist
Please confirm you have completed any of the necessary steps below.
Included test cases to demonstrate any code changes, which may be one or more of the following:
.yml
rule test cases intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withpython test/generate_parse_fixture_yml.py
or by runningtox
locally).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.