Skip to content

Subst cleanups#4869

Open
mwichmann wants to merge 1 commit into
SCons:masterfrom
mwichmann:maint/more-subst-1
Open

Subst cleanups#4869
mwichmann wants to merge 1 commit into
SCons:masterfrom
mwichmann:maint/more-subst-1

Conversation

@mwichmann

Copy link
Copy Markdown
Collaborator
  • Line breaks added for clarity
  • Code-style enforced in some places
  • In SpecialAttrWrapper.escape, an attribute is read once and stored in a local variable.
  • If all previous parts of an if-else chain have done return (or raise), there's no need for the next to be an "else". This causes one fairly large indentation change in StringSubber.expand(), as about 40 lines shift left one indent (checker observation)
  • In subst-dict the local variable is renamed from dict to substitutions to avoid "hiding" built-in dict (frequent checker grumble)

No changed behavior, so existing tests and docs are unchanged.

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

@mwichmann mwichmann added the subst Problems with quoting, substitution label Jun 27, 2026
* Line breaks added for clarity
* Code-style enforced in some places
* In SpecialAttrWrapper.escape, an attribute is read once and stored
  in a local variable.
* If all previous parts of an if-else chain have done return (or raise),
  there's no need for the next to be an "else". This causes one fairly
  large indentation change in StringSubber.expand(), as about 40 lines
  shift left one indent (checker observation)
* In subst-dict the local variable is renamed from dict to substitutions
  to avoid "hiding" built-in dict (frequent checker grumble)

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann mwichmann force-pushed the maint/more-subst-1 branch from 5db12e9 to c59efbf Compare June 27, 2026 16:03
Comment thread SCons/Subst.py
return quote_func(self.data)
else:
return self.data
data = self.data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why data = self.data instead of just using self.data?
same question why self.literal instead of self.is_literal() ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

"data": to avoid as many as three attribute lookups

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh, missed the second Q. is_literal seemed an extra call that wasn't needed:

    def is_literal(self) -> bool:
        return self.literal

Both would only have a minimal performance improvement, so if you don't want we can just drop the changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a a couple .. def is_literal from class Literal() which returns True presently..
can those get called by this logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

subst Problems with quoting, substitution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants