Skip to content
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

Fix urls fixer wrong import rewrite #270

Merged
merged 5 commits into from Oct 25, 2022

Conversation

UnknownPlatypus
Copy link
Contributor

My attempt to fix #250.

I noticed that the underlying issue is that some noop tests are actually doing rewrites.

For exemple, the following is actually triggering an erase/rewrite of the import node but since it rewrites the same thing we don't notice it:

def test_fake_noop():
    check_noop(
        """\
        from django.urls import re_path

        re_path('whatever')
        """,
        settings,
    )

I added a state_added_names variable to keep track of names that will need to be imported. Then I can only add an import with these names (minus the ones initially imported).

PS: Last commit replace the state_used_names variable with state_re_path_used because it was only needed to determine if the re_path import can be removed.

I'm unsure if it's the best way to deal with this so I'm happy to take any feed back. At least maybe this will give you some food for thoughts on your attempt.

Cheers

@UnknownPlatypus UnknownPlatypus marked this pull request as ready for review October 20, 2022 21:44
@adamchainz
Copy link
Owner

Thank you. I will review this properly in the next few days, then hopefully do a django-upgrade release with all the built-up stuff!

PS: Last commit replace the state_used_names variable with state_re_path_used because it was only needed to determine if the re_path import can be removed.

I'm unsure if it's the best way to deal with this so I'm happy to take any feed back. At least maybe this will give you some food for thoughts on your attempt.

This seems like a good approach to me!

@adamchainz adamchainz merged commit 7439a20 into adamchainz:main Oct 25, 2022
@UnknownPlatypus UnknownPlatypus deleted the fix_path_rewrite_noop branch October 25, 2022 09:21
@UnknownPlatypus
Copy link
Contributor Author

Woops, forgot about the release note, my bad. Anyway, thanks for the review and the few tweaks !

@adamchainz
Copy link
Owner

Thank you! Release coming shortly, writing a blog post for it...

@UnknownPlatypus
Copy link
Contributor Author

Awesome! I saw that you have been very productive lately with the blog posts. Really nice! Keep up the good work 😃

@sshishov
Copy link

Thank you @adamchainz and @UnknownPlatypus for fixing it in a short period of time 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undesired rewriting of import statements (pre-commit loop)
3 participants