Git Product home page Git Product logo

Comments (4)

UnknownPlatypus avatar UnknownPlatypus commented on July 30, 2024 1

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.

browniebroke avatar browniebroke commented on July 30, 2024

Actually I found a test case which matches my use case:

def test_no_datetime_import():
check_noop(
"""\
from django.utils import timezone
do_a_thing(timezone.utc)
""",
settings,
)

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.

browniebroke avatar browniebroke commented on July 30, 2024

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.

UnknownPlatypus avatar UnknownPlatypus commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.