Skip to content

Adding new StringFormat node#13997

Merged
alexisrolland merged 2 commits into
Comfy-Org:masterfrom
Pauan:feat/string-format
May 20, 2026
Merged

Adding new StringFormat node#13997
alexisrolland merged 2 commits into
Comfy-Org:masterfrom
Pauan:feat/string-format

Conversation

@Pauan
Copy link
Copy Markdown
Contributor

@Pauan Pauan commented May 20, 2026

StringFormat node

This PR adds in a new StringFormat node that just uses Python's string format method.

Similar to the MathExpression node, it supports a maximum of 26 different arguments (a-z).


The Python string format method is very useful:

  • It can be used as an easy way to concatenate strings.
  • It can be used to convert anything into a string.
  • It can format items with padding and alignment.
  • It can format numbers with zero-padding.
  • It can format numbers with a specific number of decimals.
  • And more!

@Pauan Pauan force-pushed the feat/string-format branch from f8c3d36 to 1e8fcd5 Compare May 20, 2026 00:01
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 77f6c37d-51bd-4d60-ae2c-581354715b70

📥 Commits

Reviewing files that changed from the base of the PR and between 1e8fcd5 and f0a5774.

📒 Files selected for processing (1)
  • comfy_extras/nodes_string.py

📝 Walkthrough

Walkthrough

This PR adds a new StringFormat node to the string utilities module. The node accepts an autogrowing mapping values (lowercase keys) and an f_string template, executes by calling f_string.format(**values) and returning a NodeOutput, and is registered in StringExtension.get_node_list() so it is available to the node registry.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Adding new StringFormat node' clearly and concisely describes the main change in the pull request, which is the addition of a new StringFormat node to the codebase.
Description check ✅ Passed The description is directly related to the changeset, explaining what the StringFormat node does, its capabilities, and use cases for Python's string format method.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
comfy_extras/nodes_string.py (1)

33-36: ⚡ Quick win

Consider adding error handling for format exceptions.

The str.format() method can raise KeyError (missing key in template) or ValueError (invalid format specifier) for malformed format strings. Other nodes in this file (RegexMatch, RegexExtract, JsonExtractString) catch expected exceptions and return safe defaults, providing better user experience.

Consider wrapping the format call in a try-except block to handle format errors gracefully.

♻️ Proposed error handling
     `@classmethod`
     def execute(
         cls, values: io.Autogrow.Type, f_string: str
     ) -> io.NodeOutput:
-        return io.NodeOutput(f_string.format(**values))
+        try:
+            return io.NodeOutput(f_string.format(**values))
+        except (KeyError, ValueError) as e:
+            return io.NodeOutput(f"Format error: {str(e)}")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@comfy_extras/nodes_string.py` around lines 33 - 36, The execute method in the
class (execute in comfy_extras/nodes_string.py) calls f_string.format(**values)
without guarding against formatting errors; wrap that call in a try/except that
catches KeyError and ValueError (and optionally Exception) and return a safe
default via io.NodeOutput (e.g., empty string or the original template) on
error, and log or include the error message if appropriate so behavior matches
other nodes like RegexMatch/RegexExtract/JsonExtractString.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@comfy_extras/nodes_string.py`:
- Around line 12-25: The autogrow template (io.Autogrow.TemplateNames used for
the "values" input) sets min=0 but the default f_string is "{a}", which can
KeyError when no parameters exist; update either autogrow to require at least
one parameter by changing min from 0 to 1, or make the default f_string safe
(e.g., set default to an empty string "") so the node_id "StringFormat" / input
"f_string" no longer references a missing parameter—choose and apply one of
these fixes consistently in the Schema definition.

---

Nitpick comments:
In `@comfy_extras/nodes_string.py`:
- Around line 33-36: The execute method in the class (execute in
comfy_extras/nodes_string.py) calls f_string.format(**values) without guarding
against formatting errors; wrap that call in a try/except that catches KeyError
and ValueError (and optionally Exception) and return a safe default via
io.NodeOutput (e.g., empty string or the original template) on error, and log or
include the error message if appropriate so behavior matches other nodes like
RegexMatch/RegexExtract/JsonExtractString.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 757ff8de-d5fd-4975-ad42-73261104ac09

📥 Commits

Reviewing files that changed from the base of the PR and between 6887165 and 1e8fcd5.

📒 Files selected for processing (1)
  • comfy_extras/nodes_string.py

Comment thread comfy_extras/nodes_string.py
Comment thread comfy_extras/nodes_string.py Outdated
Co-authored-by: Alexis Rolland <alexis@comfy.org>
@alexisrolland
Copy link
Copy Markdown
Member

Tested and it works fine.

{45C34A0A-C0E7-47F9-8ABF-F9D5FBBF46BB}

@alexisrolland alexisrolland self-requested a review May 20, 2026 02:23
@alexisrolland alexisrolland merged commit 7ec7b6f into Comfy-Org:master May 20, 2026
14 checks passed
@Pauan Pauan deleted the feat/string-format branch May 20, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants