Comments (7)
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.
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.
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.
I'll try to submit a PR to fix this some time later this week.
from autoimport.
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.
Removing them sounds good to me! I didn't have anything in mind -- I couldn't think of a good solution xD
from autoimport.
Awesome, thanks for taking on the implementation :)
from autoimport.
Related Issues (20)
- Add support for `python3 -m autoimport` invocation HOT 2
- Import objects by mimicking other modules HOT 2
- `typing.Literal` can cause false-positive import HOT 3
- Preserve line endings HOT 2
- Pre-generate module symbol list HOT 1
- Extra blank lines after imports are removed HOT 2
- Stdout of unmodified script should be returned even if autoimport fails to resolve libraries HOT 3
- crashes with `ValueError` when the import to remove appears twice HOT 2
- Flag to skip for `__init__.py` files HOT 3
- [Bug] handling top-level `if TYPE_CHECKING: ...` block HOT 3
- Maintenance mode. Help needed! HOT 1
- Add `--ignore-init-modules` to configurable options HOT 3
- Move away from the `xdg` package HOT 5
- Bug: Interaction between `TYPE_CHECKING` and star import HOT 1
- Bug: unused multiline import statement trigges re.error HOT 1
- Bug: Import of type "from module import (func1, func2)" can trigger ValueError HOT 1
- Mac arm64 issues HOT 1
- Option to disable "move-to-top" feature HOT 1
- Broken syntax with multiline, function-local imports HOT 3
- Allow fixing unicode files with non-ASCII characters on Windows HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autoimport.