Skip to content
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

Add type hints to main Node script #4650

Merged
merged 1 commit into from
Nov 24, 2024

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Nov 17, 2024

Kept as just the one file for now. I initially wanted to expand to FS as well, but quickly realized that this was a domino effect waiting to happen. I'd rather ensure the core concepts as they currently exist are acceptable, and catch any blunders or oversights as early as possible.

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt and RELEASE.txt (and read the README.rst).
  • I have updated the appropriate documentation

• Adjust NodeTests to account for tweaks in hinting, primarily accounting for truthiness instead of pure types
@bdbaddog bdbaddog added the maintenance Tasks to maintain internal SCons code/tools label Nov 17, 2024
@bdbaddog
Copy link
Contributor

Please leave your PR description to just the function of your PR. We don't really need color commentary on the code. We're well aware, but in general are under resourced. So we're doing the best that we can.

@mwichmann
Copy link
Collaborator

Been nibbling away at it for several years now, there's not only a shortage of bodies to do the work, but on getting refactoring (that seems to quickly get large) through the approval process - with some justification, as "it seems to be working as is" is perhaps a stronger argument than squiggly lines in an IDE or static checker spew.

The two biggest current things that are hard to annotate for are Nodes and Environments, which turn up everywhere. And one of the biggest temptations is to do something about one-line getters and setters (which work just fine as is) - so far I've mostly resisted :-). Nodes have some weird inconsistencies that checkers don't like - mismatched signatures (esp. when you get into Alias and Value nodes), inconsistent return types (what should get_contents return? str or bytes? Some do one, some the other). Environments have the minimal SubstitutionEnvironment as the base of Base (right?) which is not usable by itself, and the OverrideEnvironment which is really a kind of protocol - it works like, but isn't a child class of, any of the others.

I'll respect @bdbaddog wishes and not go on.

@@ -711,30 +711,30 @@ def test_set_always_build(self) -> None:
node = SCons.Node.Node()
node.set_always_build()
assert node.always_build
node.set_always_build(3)
assert node.always_build == 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These things are weird, in the code noclean, nocache, precious and always_build are used like bools, but there are some comments about leaving a couple of them as ints, and the unit tests seem to treat them as ints that could have values other than 0/1 (None seems to be possible too in some cases). That's probably not necessary because of the way that code is written - the IDX function the tree printer uses always converts to a bool anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments appear to come from a time before the IDX function was a thing, and no other parts of the code appear to utilize these for anything other than boolean evaluation. The only exception was this test file, but it doesn't seem to actually be to any end; making them evaluate truthiness instead felt more applicable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments appear to come from a time before the IDX function was a thing, and no other parts of the code appear to utilize these for anything other than boolean evaluation. The only exception was this test file, but it doesn't seem to actually be to any end; making them evaluate truthiness instead felt more applicable

perhaps I'll take a whack at converting them in a future PR.

@Repiteo
Copy link
Contributor Author

Repiteo commented Nov 17, 2024

Apologies for coming off as hostile; that wasn't my intent. Y'all are obviously just dealing with the hand you've been dealt, the last thing I wanna do is compound it by preaching to the choir

@@ -652,7 +659,7 @@ def get_executor(self, create: int=1) -> Executor:
try:
act = self.builder.action
except AttributeError:
executor = SCons.Executor.Null(targets=[self]) # type: ignore
executor = SCons.Executor.Null(targets=[self]) # type: ignore[assignment]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting case. While it's currently just suppressing the type-change for the Null executor, this feels like it could just return None instead. It'd be more in-line with how other classes (eg: Scanners) handle their optional arguments/returns. Left it alone because that'd obviously be a huge change, but it's something I've been thinking about

@bdbaddog bdbaddog merged commit c580a72 into SCons:master Nov 24, 2024
7 of 8 checks passed
@Repiteo Repiteo deleted the node-explicit-types branch November 24, 2024 23:37
@mwichmann mwichmann added this to the NextRelease milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Tasks to maintain internal SCons code/tools
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

3 participants