refactor(python): rename FormattableString field from str to fmt#4637
Merged
Conversation
The Python representation of FormattableString used a field literally named `str`, producing an object expression with a `@property def str`. While this runs correctly (the `-> str` return annotation resolves to the builtin under PEP 563, and Pyright accepts it), Astral's `ty` type checker resolves the annotation against the class-scoped `str` property and reports a false-positive `invalid-type-form` error. Rename the internal field to `fmt`, which sidesteps the builtin-name collision entirely. The field is internal to the `formattableString` replacement (written by `Create`, read by `get_Format`), so the change is fully self-contained. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3abe301 to
89f9d94
Compare
Contributor
Python Type Checking Results (Pyright)
Excluded files with errors (4 files)These files have known type errors and are excluded from CI. Remove from
|
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.
Problem
The Python representation of
FormattableStringused a field literally namedstr, so a$"...{x}..."interpolation typed asFormattableStringcompiled to an object expression with a@property def str:This runs correctly and Pyright accepts it — under PEP 563 (
from __future__ import annotations) the-> strreturn annotation resolves to the builtin (get_type_hintsconfirms{'return': <class 'str'>}), and the property never shadows the builtin since attribute names live in a separate namespace.However, Astral's
tyresolves the annotation against the class-scopedstrproperty and reports a false positive:Fix
Rename the internal field
str→fmtin the PythonformattableStringreplacement. The field is internal to that one function (written byCreate, read byget_Format), so the change is fully self-contained —GetArgument/GetArguments/ArgumentCountuse the separateargsfield, andGetStrings()is JS-only.Verification
./build.sh test python)ty check temp/tests/Python/test_string.py→All checks passed!🤖 Generated with Claude Code