-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
timezone.utc
isn't replaced when datetime
isn't imported
#409
Comments
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.utc
isn't replaced when passed as keyword argumenttimezone.utc
isn't replaced when datetime
isn't imported
See #389 (comment) and related issue for a similar problem, adding import is non trivial because it could be shadowed by anything named |
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 As an inspiration, we might look at libCST, which has a fixer to add import. |
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)
|
Python Version
3.11
Django Version
4.2
Package Version
1.15.0
Description
I have a case where
timezone.utc
isn't replaced by django-upgrade. This was introduced in #169 (requested in #135) and as far as I can tell, my use case isn't part of the tests, but I'm not sure how feasible it is:I assume it's because the value is a keyword argument? I would expect it to replace it as:
Although now that I look more closely, my use case is slightly more complex, as the file also uses
timezone.now()
, in case it matters. All in all, the expected behaviour would probably be:The text was updated successfully, but these errors were encountered: