-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
[internal] Somewhat simplify config parsing #14699
Conversation
- Simplify Config.get to always return a string. It was being used that way in practice everywhere within the options system (which does the type conversion later). The only place Config.get was used for type conversion was in the special case of cli.alias, which the options bootstrapper reads directly from config. So the conversion in that one case was inlined. As a byproduct, gets rid of the default= arg to Config.get, and always returns None if the value doesn't exist, since the default= arg was, again, only used in that one special case. - Fix the type signature of get_value, which can never in fact return None. - Use our own exception types instead of borrowing the ones from configparser, now that ini parsing is a distant memory. This makes the Config class easier to reason about. [ci skip-rust] [ci skip-build-wheels]
This is pre-work to make it simpler to tackle #14679 |
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.
Yay! Bye bye configparser.
If it helps at all, I think it's very reasonable to get rid of our abstract class for Config
vs our Toml implementation. It seems very very unlikely we'll want to support more config file formats. Right now there's over-generalization, like the difference from .get()
vs .get_value()
is unnecessary.
def get(self, section, option, type_=str, default=None): | ||
"""Retrieves option from the specified section (or 'DEFAULT') and attempts to parse it as | ||
type. | ||
def get(self, section, option) -> str | None: |
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.
This should probably have type hints too:
def get(self, section, option) -> str | None: | |
def get(self, section: str, option: str) -> str | None: |
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.
Fine to do in followup
Btw this should be |
Simplify Config.get to always return a string.
It was being used that way in practice everywhere within
the options system (which does the type conversion later).
The only place Config.get was used for type conversion was
in the special case of cli.alias, which the options bootstrapper
reads directly from config. So the conversion in that one
case was inlined.
As a byproduct, gets rid of the default= arg to Config.get,
and always returns None if the value doesn't exist, since
the default= arg was, again, only used in that one special case.
Fix the type signature of get_value, which can never
in fact return None.
Use our own exception types and constants, instead of
borrowing the ones from configparser, now that ini parsing is
a distant memory.
This makes the Config class easier to reason about.
[ci skip-rust]
[ci skip-build-wheels]