Git Product home page Git Product logo

Comments (7)

lyz-code avatar lyz-code commented on June 23, 2024 1

Hey @Jasha10 sorry for the delay these days answering you, I didn't have much time. As always, thank you for your time opening issues and proposing fixes

from autoimport.

lyz-code avatar lyz-code commented on June 23, 2024 1

I'd vote to remove them. If someone complains in the future about this behaviour, we can always add a configuration option to prevent them to be removed. What did you have in mind?

from autoimport.

lyz-code avatar lyz-code commented on June 23, 2024 1

Hey @Jasha10 , I've been working on this issue.

The original issue was the use of noqa. autoimport only ignores the lines that have noqa: autoimport, so the next snippet works:

    source = dedent(
        """\
        # tmp.py
        from typing import Any  # noqa: autoimport
        from typing import TypeVar
        """
    )
    desired_source = dedent(
        """\
        # tmp.py

        from typing import Any  # noqa: autoimport
        """
    )

I think it's interesting to specify what kind of noqa you want to use, is very cumbersome for you to write the : autoimport?

I've also fixed the removal of the comment on simple import statements, on multiline will still fail, but I'm not sure it's a common case. If it is, whenever it occurs we can open another issue.

It should work on 0.9.0, if it doesn't please reopen the issue

from autoimport.

Jasha10 avatar Jasha10 commented on June 23, 2024

I'll try to submit a PR to fix this some time later this week.

from autoimport.

Jasha10 avatar Jasha10 commented on June 23, 2024

My pleasure! It turns out the bug was with comments in general, not with the word 'noqa' specifically.

What's the desired behavior for lines that have comments?
For example: I was able to get the following test case working by modifying autoimport's regex patterns:

    source = dedent(
        """\
        import os  # comment 1
        import sys  # comment 2

        os.getcwd()
        """
    )
    desired_source = dedent(
        """\
        import os  # comment 1
        # comment 2

        os.getcwd()
        """
    )

BUT, I'm not sure if preserving comment2 like that is desirable. For example, the user might have made a comment about the import, and now the comment makes no sense since the import is gone.

@lyz-code, what do you think is the best behavior for comments on imports that would be removed?

from autoimport.

Jasha10 avatar Jasha10 commented on June 23, 2024

Removing them sounds good to me! I didn't have anything in mind -- I couldn't think of a good solution xD

from autoimport.

Jasha10 avatar Jasha10 commented on June 23, 2024

Awesome, thanks for taking on the implementation :)

from autoimport.

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.