-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Mypy (type) directives no longer relevant after running isort check #10516
Comments
Thanks for the clear write-up. I worry about the behavior of Regardless I agree we should not be breaking this. Without further investigation, I think it would be reasonable to mark the fix as unsafe if we detect suppression comments. |
@zanieb I think we shouldn't look at this issue in isolation of For the formatter, pragma comments are handled differently in that they are excluded from the line-width computation. However, we decided not to implement any special placement logic for pragma comments (or suppress formatting) because a) the correct placement depends on the specific pragma comment, e.g. I'm open to suggestions for improving pragma comment placement, but I fear moving some pragma comments manually might be necessary. This is inherent to the design decision to encode semantic meaning into comments with no grammar rules. |
Possibly mypy requires the |
I've run into this issue as well and figured I'd post my example in case helpful:
As indicated in the Issue description, removing the three specific |
I'm struggling to create a minimal example, so bear with this more complicated one:
In the keyring project, I'm exploring introducing the isort ("I") linter. When I add it and invoke it on the project, it produces a diff in the
keyring/_compat.py
module:After making that change, the mypy tests start failing:
Note that running mypy from another environment will not suffice - you need mypy in the environment where keyring was installed in order to get the right dependencies and stubs.
Moving the
# type: ignore[no-redef]
directive to the line above fixes the issue:Relatedly, note also that the coverage directive, which was previously not well placed, also now misses line 7 where it previously exempted it.
What I expect is that an isort
--fix
should retain the semantic meaning of directives in comments, or at least protect the rewrite in an "unsafe" fixer.The text was updated successfully, but these errors were encountered: