Skip to content

[ty] Add support for PEP 750 t-strings - #20085

Merged
dylwil3 merged 6 commits into
astral-sh:mainfrom
dylwil3:ty-t-strings
Aug 25, 2025
Merged

dylwil3 merged 6 commits into
astral-sh:mainfrom
dylwil3:ty-t-strings

Conversation

@dylwil3

@dylwil3 dylwil3 commented Aug 25, 2025 •

Copy link
Copy Markdown
Collaborator

This PR attempts to add support for inferring string.templatelib.Template for t-string literals.

First PR of this kind so apologies in advance if I've made a mess of things! Also this is low priority so feel free to ignore.

Diff is relatively small but feel free to review commit-by-commit if it's more convenient.

Also tested LSP:
demo

@dylwil3 dylwil3 added the ty The ty type checker label Aug 25, 2025
Comment thread crates/ty_python_semantic/src/types/class.rs
@github-actions

github-actions Bot commented Aug 25, 2025 •

Copy link
Copy Markdown
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Comment on lines 5193 to +5117
fn known_class_roundtrip_from_str() {
let db = setup_db();
let mut db = setup_db();
Program::get(&db)
.set_python_version_with_source(&mut db)
.to(PythonVersionWithSource {
version: PythonVersion::latest_preview(),
source: PythonVersionSource::default(),
});

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let me know if you'd like me to handle this differently, and/or add an assertion to remind us to modify this once the latest supported version is Python 3.14

@github-actions

github-actions Bot commented Aug 25, 2025 •

Copy link
Copy Markdown
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@dylwil3 dylwil3 changed the title [ty] Add support for PEP 750 t-strings [ty] Add support for PEP 750 t-strings Aug 25, 2025

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!

Comment thread crates/ty_python_semantic/resources/mdtest/t_strings.md
Comment thread crates/ty_python_semantic/src/types/class.rs Outdated
Comment thread crates/ty_python_semantic/src/types/class.rs
@dylwil3
dylwil3 enabled auto-merge (squash) August 25, 2025 18:39
@dylwil3
dylwil3 disabled auto-merge August 25, 2025 18:39
@dylwil3
dylwil3 enabled auto-merge (squash) August 25, 2025 18:46
@dylwil3
dylwil3 merged commit ef4897f into astral-sh:main Aug 25, 2025
37 checks passed
@dylwil3
dylwil3 deleted the ty-t-strings branch August 25, 2025 18:51
second-ed pushed a commit to second-ed/ruff that referenced this pull request Sep 9, 2025
This PR attempts to adds support for inferring`string.templatelib.Template` for t-string literals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants