Comments (2)
Oh fun.
Turns out the tokenize leaves f-strings as a single token:
In [1]: import tokenize_rt
In [2]: tokenize_rt.src_to_tokens('f"{x()}"')
Out[2]:
[Token(name='STRING', src='f"{x()}"', line=1, utf8_byte_offset=0),
Token(name='NEWLINE', src='', line=1, utf8_byte_offset=8),
Token(name='ENDMARKER', src='', line=2, utf8_byte_offset=0)]
Whilst the AST parses them, presumably through a second internal tokenization step:
In [3]: import ast
In [4]: print(ast.dump(ast.parse('f"{x()}"'), indent=2))
Module(
body=[
Expr(
value=JoinedStr(
values=[
FormattedValue(
value=Call(
func=Name(id='x', ctx=Load()),
args=[],
keywords=[]),
conversion=-1)]))],
type_ignores=[])
The fixer finds the AST Name
for the old name, but its callback is then never called because there's no token corresponding to the Name
.
I'm not sure what we can do here... perhaps recursively apply the fixers on FormattedValue
s. Maybe there's something in pyupgrade to copy.
from django-upgrade.
The pyupgrade issue ( asottile/pyupgrade#572 ) was just resolved because it "just works" on Python 3.12. This is thanks to the PEP that modified how f-strings are parsed. I will add a 3.12+ test here to check this is also the case for django-upgrade.
from django-upgrade.
Related Issues (20)
- `STORAGES` setting from Django 4.2 HOT 6
- Parse Django version from requirements.txt HOT 6
- Extend test_http_headers fixer to cover `AsyncClient` and `AsyncRequestFactory`
- Templates - length_is
- Django 5.0: Drop `.choices` for model field `choices` parameters
- admin_site.register -> @admin.register results in "undefined name 'admin_site'" HOT 5
- Auto create Meta.index values for index_together usages HOT 11
- NullBooleanField fixer can remove still-used import
- Django 5.1: Fixer for CI*Field - db_collation replacement HOT 1
- does it require internet access? HOT 3
- default_app_config fixer HOT 3
- Rewrite `queryset.filter(pk=obj.pk).exists()` to `queryset.contains(obj)` HOT 3
- Strip skip decorators for old Django versions
- Django 4.1 Deprecated MemcachedCache HOT 1
- Default file storage is unset by django-upgrade HOT 1
- Check for unnecessary r strings in path HOT 3
- Support removal of `django.core.urlresolvers` on Django 2.0 HOT 5
- Cache support HOT 3
- Add `@admin.display` decorators in models file too HOT 5
- Introduce instruction on how to contribute with the project
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-upgrade.