Comments (6)
The import should only be added if something else in the file needs it - can you see any URL's that are being modified as well?
from django-upgrade.
Nothing else is being modified.
I believe this happens:
- I ran
precommit run django-upgrade --all-files
and initially, things were modified such that the new import statements made sense together with URL pattern changes - Upon "git commit", I see that subsequent pre-commit hooks make additional changes
- I commit the changes made by pre-commit but since django-upgrade is ALSO installed as a pre-commit, I now see that it has made new import statement changes as described above (but nothing else got changed)
from django-upgrade.
Thanks, replicated with an extra test in test_django_urls.py
:
def test_two_imported_used():
check_noop(
"""\
from django.urls import path
from django.urls import re_path
path('whatever')
re_path('whatever')
""",
settings,
)
The problem is that the call-rewriter is registering re_path
as "used" when it encounters it (even though it doesn't rewrite it to path
), which makes the import-rewriter rewrite it.
I think the import rewriting code here could do with some improvements to support all import styles.
from django-upgrade.
The same issue is happening for us.
We are also using one line per import and the library is rewriting the import and then isort rewrite it back.
Means we cannot use this pre-commit
until the issue is fixed.
from django-upgrade.
Understood, I started lookign a fix in #255, treating it as a release blocker at least.
from django-upgrade.
Thank you for the update @adamchainz 👍
from django-upgrade.
Related Issues (20)
- 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
- Django 6.0: Remove `FORMS_URLFIELD_ASSUME_HTTPS` transitional setting
- `timezone.utc` isn't replaced when `datetime` isn't imported HOT 4
- Rewrite `redirect(reverse(...))` calls to `redirect(...)` HOT 4
- `.choices` dropped for choices not subclassing the `*Choices` class HOT 6
- `request.is_ajax()` method is removed since Django 4.0. HOT 1
- Convert is_authenticated() to is_authenticated HOT 1
- Add fixer for django.db.models.AutoField in Django 3.2 HOT 1
- Template Tag "trans" to "translate" HOT 2
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.