Skip to content

Check whether Constant value is str#1333

Merged
ericwb merged 1 commit into
PyCQA:mainfrom
ericwb:utils_ast_constant
Nov 23, 2025
Merged

Check whether Constant value is str#1333
ericwb merged 1 commit into
PyCQA:mainfrom
ericwb:utils_ast_constant

Conversation

@ericwb
Copy link
Copy Markdown
Member

@ericwb ericwb commented Nov 23, 2025

This change fixes a case of a missed check on the value of a ast.Constant to be a str or not. PR #1323 fixed many of these as part of the Python 3.14 compatibility since ast.Str was removed. So when checking ast.Constant, the value can many types of literals, not just str.

Note: I tested before and after this fix using the repo given in the issue.

Fixes #1332

This change fixes a case of a missed check on the value
of a ast.Constant to be a str or not. PR PyCQA#1323 fixed
many of these as part of the Python 3.14 compatibility
since ast.Str was removed. So when checking ast.Constant,
the value can many types of literals, not just str.

Fixes PyCQA#1332

Signed-off-by: Eric Brown <eric_wade_brown@yahoo.com>
@ericwb ericwb self-assigned this Nov 23, 2025
@ericwb ericwb added the bug Something isn't working label Nov 23, 2025
@ericwb ericwb requested a review from Copilot November 23, 2025 18:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Python 3.14 compatibility issue in the concat_string utility function by adding a type check to ensure only string values from ast.Constant nodes are joined together. This addresses a regression from PR #1323, which removed support for the deprecated ast.Str node type in favor of ast.Constant, but missed validating that constant values are actually strings before attempting to join them.

Key Changes:

  • Added isinstance(x.value, str) check in the list comprehension filter to prevent non-string constants (integers, booleans, etc.) from being passed to str.join()
  • Follows the same pattern already established in injection_sql.py for handling ast.Constant nodes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal error running hardcoded_sql_expressions on file expected str instance, int found

3 participants