Make the new options module fully type safe
This fixes all of the issues in the options module, as well as fixing type safety issues introduced by it. This really falls into four parts:
- fix the pre-existing issues with the
UserOptionclasses - clean up some uses of
Anythat would hide real issues - Correct annotations for the OptionKey type that were broken
- add missing annotations to the
OptionStoreclass.
This fully supersedes #13616
@dnicolodi: I've added an explicit method for checking the choices, so all of that is hidden inside the options module, which I think is a bit more elegant than having coredata poke at the internals of the UserOption classes. I've also added a Range[T] implementation. I'm not sure on it, it does make some things nicer, but its more code and makes other things more complex, so for now I haven't folded into the series itself, but left it separate so it can be evaluated separately.
The suggestion to add the Range type was done in the optic of allowing to compare the choice member of enumerated options types and int option types transparently, thus it is somehow alternative to your choices_are_different() function. It does not add much value otherwise.
@dnicolodi fixed the typo, and dropped the range patch. I played around with getting better error messages, and just felt like it wasn't worth the amount of code involved.
I cherry-picked a few (more) of these to master. Haven't taken a close look at the rest and it's getting late on Friday.
This probably conflicts with option refactor quite badly. Which one should be merged first?
I think this one, and then following that: https://github.com/mesonbuild/meson/pull/13737. Which would give us a really solid base of typing guarantees to build the option refactor on top of so that we have a fairly good idea that things work across the changes. I've actually started doing that rebase on top of 13737, and I've found several issues already. I'll try to push that work upstream somewhere we can look at it after a bit, right now I need to go start dinner.
I'm also saying that because I'll put my money where my mouth is. Having mypy typing catches lots of real issues before they go to production.
How ready is this for merging?
From my perspective I've addressed all of the review feedback, with the exception of the question about __post_init__ vs init=False. I have a preference but if the wider consensus is to go the other way I can do that.
I don't really have a preference on that, I just want this in so optionrefactor can proceed.
Lint failure is unrelated.