Code Monkey home page Code Monkey logo

Comments (6)

adamchainz avatar adamchainz commented on June 18, 2024

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.

benjaoming avatar benjaoming commented on June 18, 2024

Nothing else is being modified.

I believe this happens:

  1. 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
  2. Upon "git commit", I see that subsequent pre-commit hooks make additional changes
  3. 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.

adamchainz avatar adamchainz commented on June 18, 2024

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.

sshishov avatar sshishov commented on June 18, 2024

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.

adamchainz avatar adamchainz commented on June 18, 2024

Understood, I started lookign a fix in #255, treating it as a release blocker at least.

from django-upgrade.

sshishov avatar sshishov commented on June 18, 2024

Thank you for the update @adamchainz 👍

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.