Skip to content

fix(iohandler): drop deprecated ast.Str and .s usage - #6846

Closed
Barry-Lenhart wants to merge 1 commit into
keephq:mainfrom
Barry-Lenhart:fix-ast-str-deprecation
Closed

Barry-Lenhart wants to merge 1 commit into
keephq:mainfrom
Barry-Lenhart:fix-ast-str-deprecation

Conversation

@Barry-Lenhart

Copy link
Copy Markdown

What

IOHandler's function-call parsing (keep/iohandler/iohandler.py) checks literals with isinstance(arg, ast.Str) or isinstance(arg, ast.Constant) and reads arg.s.

Since Python 3.8 the parser emits ast.Constant for every literal, and ast.Str / .s are deprecated aliases:

  • on Python 3.12 and 3.13 they emit DeprecationWarnings every time a templated function call is rendered,
  • on Python 3.14 ast.Str is removed entirely, so this line would raise AttributeError.

The existing isinstance(..., ast.Constant) check already covers every case, so this uses it alone and reads .value (which .s was an alias for) in both places, for positional and keyword arguments.

Testing

On Python 3.12:

  • pytest tests/test_iohandler.py: 68 passed, same as before.
  • With -W error::DeprecationWarning:keep.iohandler.iohandler: 27 of the 68 tests fail on main and all 68 pass with this change.
  • str(node.s) and str(node.value) give identical results for string, int, float, True and None literals.
  • ruff check (the pinned 0.11.4) passes, and black suggests no changes to the touched lines.

I used an AI assistant (Claude) to help find this, make the change, and draft this description. I reviewed the change and ran the tests myself.

Since Python 3.8 the parser emits ast.Constant for every literal, and
ast.Str / the .s attribute are deprecated aliases that emit a
DeprecationWarning on Python 3.12+ (ast.Str is removed in Python 3.14).
The existing `isinstance(..., ast.Constant)` check already covers every
case, so use it alone and read `.value` instead of `.s`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Barry seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

Copy link
Copy Markdown
Contributor

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

@Barry-Lenhart

Copy link
Copy Markdown
Author

Closing this, as I'm not able to sign the CLA at the moment. For anyone picking it up: the fix is just using the existing isinstance(..., ast.Constant) check on its own and reading .value instead of .s in keep/iohandler/iohandler.py (two places). ast.Str is removed in Python 3.14, and on 3.12 27 of the 68 tests in tests/test_iohandler.py fail with -W error::DeprecationWarning. Thanks!

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