Comments (4)
See #389 (comment) and related issue for a similar problem, adding import is non trivial because it could be shadowed by anything named datetime
in scope. safely doing that imply tracking scopes and declared named I suppose
from django-upgrade.
Actually I found a test case which matches my use case:
django-upgrade/tests/fixers/test_utils_timezone.py
Lines 45 to 53 in 5afcc45
I have timezone
imported, but no datetime
import. I can see that test case was added in #227. Looks like it was intentionally decided to not handle this case, I assume there are some complications with adding a datetime import...
from django-upgrade.
Makes sense. I see that it's actually listed as a requirement for this fixer to work in the README. Going to close this, as I don't have a good suggestion on how to implement this safely... It seems relatively unlikely that something in scope is called datetime
without having datetime
imported, but it's probably better to err on the safe side.
As an inspiration, we might look at libCST, which has a fixer to add import.
from django-upgrade.
Their fixer seems to have the same issue, they don't really check scopes because it would be too expensive. See Instagram/LibCST#1024 (comment)
I agree,
AddImportsVisitor
won't be able to do a perfect job all the time unless we include expensive scope analysis into it
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
- 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.