fix(iohandler): drop deprecated ast.Str and .s usage - #6846
Closed
Barry-Lenhart wants to merge 1 commit into
Closed
Barry-Lenhart wants to merge 1 commit into
Barry-Lenhart wants to merge 1 commit into
Conversation
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>
|
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. |
Contributor
|
No linked issues found. Please add the corresponding issues in the pull request description. |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
IOHandler's function-call parsing (keep/iohandler/iohandler.py) checks literals withisinstance(arg, ast.Str) or isinstance(arg, ast.Constant)and readsarg.s.Since Python 3.8 the parser emits
ast.Constantfor every literal, andast.Str/.sare deprecated aliases:DeprecationWarnings every time a templated function call is rendered,ast.Stris removed entirely, so this line would raiseAttributeError.The existing
isinstance(..., ast.Constant)check already covers every case, so this uses it alone and reads.value(which.swas 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.-W error::DeprecationWarning:keep.iohandler.iohandler: 27 of the 68 tests fail onmainand all 68 pass with this change.str(node.s)andstr(node.value)give identical results for string, int, float,TrueandNoneliterals.ruff check(the pinned 0.11.4) passes, andblacksuggests 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.