Skip to content

t-strings in the annotation STRING format #133551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JelleZijlstra opened this issue May 7, 2025 · 0 comments
Closed

t-strings in the annotation STRING format #133551

JelleZijlstra opened this issue May 7, 2025 · 0 comments
Labels
3.14 bugs and security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 7, 2025

Bug report

Bug description:

Currently t-strings are not recovered correctly in the STRING format in annotations:

>>> def f(x: t"a{int}"): pass
... 
>>> import annotationlib
>>> annotationlib.get_annotations(f, format=annotationlib.Format.STRING)
{'x': "Template(strings=('a', ''), interpolations=(Interpolation(int, 'int', None, ''),))"}

I think we can do better there.

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

@JelleZijlstra JelleZijlstra added the type-bug An unexpected behavior, bug, or error label May 7, 2025
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 7, 2025
I don't know why you'd use t-strings in annotations, but now if you do,
the STRING format will do a great job of recovering the source code.
@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.14 bugs and security fixes stdlib Python modules in the Lib dir topic-typing and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels May 7, 2025
JelleZijlstra added a commit that referenced this issue May 8, 2025
I don't know why you'd use t-strings in annotations, but now if you do,
the STRING format will do a great job of recovering the source code.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 8, 2025
I don't know why you'd use t-strings in annotations, but now if you do,
the STRING format will do a great job of recovering the source code.
(cherry picked from commit 90f476e)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JelleZijlstra added a commit that referenced this issue May 8, 2025
…3628)

gh-133551: Support t-strings in annotationlib (GH-133553)

I don't know why you'd use t-strings in annotations, but now if you do,
the STRING format will do a great job of recovering the source code.
(cherry picked from commit 90f476e)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 8, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 8, 2025
…ythonGH-133634)

(cherry picked from commit 0a3ccb8)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JelleZijlstra added a commit that referenced this issue May 8, 2025
…H-133634) (#133636)

gh-133551: Skip annotationlib for now in ast roundtrip tests (GH-133634)
(cherry picked from commit 0a3ccb8)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants