-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
Import headings in blocks lead to check errors #1301
Comments
Thanks for reporting! I'm a bit confused, but I think I've determined what it is you want: Currently, given code = """
try:
import logging
from os import abc, path
except ImportError:
pass
""" if you do """
try:
# stdlib
import logging
from os import abc, path
except ImportError:
pass
""" Which means that the check above the above example will correctly spot the inconsistency. My best guess is that you instead expected: """
try:
import logging
from os import abc, path
except ImportError:
pass
""" Which would mean you want a way to not have import headings apply to nested import sections? Is that correct? Let me know if I'm off base here in any way! |
@timothycrosley thank you for your quick response (and of course for the great tool you provide) Well now I am a bit confused. I would expect that """
try:
# stdlib
import logging
from os import abc, path
except ImportError:
pass
""" I do not understand your
|
Yes for the second example isort does and should return true for check, because the comment exists, but for the first (which is the same as the issue) isort returns False on check because the comment is missing - so it's not valid based on the configuration set |
Yes, first it shall complain. But after reformatting (and getting the correct code) it still complains and isort will never apply any changes anymore. code = """
try:
# stdlib
import logging
from os import abc, path
except ImportError:
pass
"""
extra_config = {"import_heading_stdlib": "stdlib"}
isort.check_code(code, **extra_config)
ERROR: Imports are incorrectly sorted and/or formatted.
False but should return |
Sorry for my confusion! And thank you for bearing with me! I finally was able to reproduce the error, fix it, and push that fix to PYPI. If you download the latest 5.0.9 release of isort, this issue should no longer be present. Thanks! ~Timothy |
Wow, thank you very much! I checked and confirm it is working perfectly now. |
When using
import_heading
for a section and the import is not at module level the isort-ed code is now perfectly formatted (#1290) but it does not pass the check anymore.Here's a simple example for demonstration
When running
isort
on the command-line it says that the file is fixed but nothing is changed and this leads to an infinite loop.The text was updated successfully, but these errors were encountered: