-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make coredata and environment fully type safe #13737
Draft
dcbaker
wants to merge
20
commits into
mesonbuild:master
Choose a base branch
from
dcbaker:submit/type-safe-coredata
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This provides a method to get choices for options in a printable form. The goal is to make refactoring options simpler.
This saves a *tiny* bit of typing, but at the cost of requiring either the current solution of throwing up our hands and saying "typing is too hard, better to have bugs!" or an extensive amount of `TypedDict`s, `overloads`, and a very new version of mypy. Let's get our type safety back, even if it means writing a little bit more code.
This reduces code, makes this clearer, and will be a nice step toward the goal of getting everything typesafe
This will allow us to take choices out of the UserOption class, which doesn't actually use this attribute.
Which wants a string, but then passes that string to a function that wants an OptionKey, which means that we'll always miss the lookup in BULITIN_DIR_NOPREFIX_OPTIONS, and return the default. The only case this gets used we cast an OptionKey to str, and then pass that. So instead, do the cast inside the function when necessary and pass the OptionKey
They are very similar, but they are not exactly the same. By splitting them we can get full type safety, and run mypy over the options.py file!
This allows us to hide type differences inside the options module, but still get accurate change information.
…on types The fact that UserOption is generic is really an implementation detail, not something to be used publicly. So by having an `AnyOptionType` alias, we can get better type checking, as can be seen by the patch as a whole. One of the big fixes it replace open-coded equivlalents of `MutableKeydOptionDictType` with that type alias.
dcbaker
force-pushed
the
submit/type-safe-coredata
branch
2 times, most recently
from
October 1, 2024 19:59
1300e3a
to
e350d38
Compare
It's not re-exported from options, so it should come from coredata
This allows us to get rid of more Any use, so there's a lot of typing fallout.
These include things like not narrowing unions and boolean error handling
We don't actually allow anything except elementry types (`str`, `bool`, `int`, `array[str]`) here, so we can tighten the typing. This in turn helps us to simplify the typing in environment.py
This as much as anything is to stop lying to envconfig about the potential types it will be given.
There were two issues, one was that we were calling from an interpreter method to an interpreter method, and second that we needed to narrow some option values.
dcbaker
force-pushed
the
submit/type-safe-coredata
branch
from
October 1, 2024 20:31
e350d38
to
bd136fd
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I give you a mypy compliant environment and coredata. There isn't actually that much here once we get the options module safe. With this in place the next big roadblock to full type safety is the build module.
This is built on #13620, and thus this is a draft