-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Remove the BaseOption class #14312
base: master
Are you sure you want to change the base?
Remove the BaseOption class #14312
Conversation
We have the OptionKey in the one caller that exists already, and this allows us to do a hash lookup instead of a linear walk.
Initially this is just used for getting builtin option default values, but it could be extended to show the default value of an option in the summary and in the introspection API.
6de8803
to
a90ab0f
Compare
mesonbuild/compilers/compilers.py
Outdated
|
||
base_options = {key: base_opt.init_option(key) for key, base_opt in BASE_OPTIONS.items()} | ||
def _make_option_key(opt: options.AnyOptionType) -> T.Tuple[OptionKey, options.AnyOptionType]: | ||
return OptionKey(opt.name), opt |
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.
should we assert opt.name.startswith('b_')
?
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.
I think I'd prefer to use a unittest for that if we want to enforce that, to avoid runtime overhead
This class only served one purpose, to avoid typing the name of the option twice. Unfortunately the way it was implemented made getting the type checking right difficult, and required storing the same data twice. This patch replaces this approach with a dictionary comprehension that creates the OptionKey from the UserOption. This allows us to initialize a single dictionary once, avoid typing the name twice, delete lines of code, and get better type safety. As an added bonus, it means that the exported data from the module can be marked module constant, ie, ALL_CAPS.
a90ab0f
to
e7f4085
Compare
⚔️ conflicts. |
This class ends up being a really complicated, not type safe, way of creating a dictionary of
OptionKey: UserOption
without typing the name twice. We can get the same result with a function that constructs the OptionKey from the UserOption, but with better type safety. It also remove a layer of initialization at startup.