Skip to content
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

Merged
merged 6 commits into from Dec 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/sqlfluff/core/config.py
Expand Up @@ -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)
Copy link
Contributor Author

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

section_dict = self.get_section(section)
Copy link
Contributor Author

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
Comment on lines +619 to +620
Copy link
Contributor Author

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


return section_dict.get(val, default)

def get_section(self, section: Union[str, Iterable[str]]) -> Union[dict, None]:
"""Return a whole section of config as a dict.
Expand Down