Strict null checking part 2 - #15957
Draft
dcbaker wants to merge 24 commits into
Draft
Conversation
This was purely a bad annotation situation.
Which could return None via a default value, but the annotation (and the uses) don't allow for it.
This value isn't actually null if `yielding` is true.
…u_family This makes the typing system safer.
It's never not passed, so making it optional just complicates the typing.
This fixes issues in mintro.py
We need to use `.get(arg) or ''`, since the value can itself be `None`.
Since we have methods in BuildTarget that set it.
Which has the correct type internally, but the return type is missing an optional annotation
This fixes a strict null where self.name is None for a short time.
Int he case of rename we can use an InitVar to ensure that `self.rename` is never None. For data_type we just annotate that it can be `str | None`.
It's passed into a function that requires the backend, and doesn't accept None. So we need to get it in every case.
bonzini
reviewed
Jun 26, 2026
| else: | ||
| self.extra_depends.append(t) | ||
| else: | ||
| path = self.generator.exe.get_path() |
Contributor
There was a problem hiding this comment.
Can this be changed by swapping the if and the else like
if (path := self.generator.exe.get_path()) is not None:
...
else:
assert isinstance(self.generator.exe, LocalProgram)
?
bonzini
reviewed
Jun 26, 2026
|
|
||
| not_token.bytespan = (not_token.bytespan[0], in_token.bytespan[1]) | ||
| not_token.value += temp_node.whitespaces.value + in_token.value | ||
| if temp_node.whitespaces is not None: |
Contributor
There was a problem hiding this comment.
is None cannot happen here because this is the whitespace between not and in.
bonzini
reviewed
Jun 26, 2026
| d = d.get_target() | ||
| elif isinstance(d, programs.Program): | ||
| path = d.get_path() | ||
| path = unwrap(d.get_path()) |
Contributor
There was a problem hiding this comment.
As elsewhere, the three cases are:
- not found (path is None)
- LocalProgram (currently, either path is not None or exception)
- ExternalProgram (path is not None)
If LocalProgram can be changed to return None instead of raising an exception, then get_path() can be used first and followed by an assert isinstance(d, LocalProgram).
bonzini
reviewed
Jun 26, 2026
| raise MesonBugException('Cannot call get_command() on program that is a build target.') | ||
|
|
||
| def get_path(self) -> str: | ||
| def get_path(self) -> str | None: |
Contributor
There was a problem hiding this comment.
This currently can never happen - a LocalProgram can only wrap an ExternalProgram that was found, and therefore whose path is not None. But this change is okay if the raise below is replaced by return None as detailed elsewhere.
This file contains hidden or 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
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.
Here's a second set of strict typing fixes, This is a small subset of the work I have toward this, but this bit seemed like already a lot of commits, and is pretty self contained.