-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Ignore specific lines #500
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
Comments
Check this issue #486 , right now you can't, but there are some things to do before to allow that. |
This is something that I'd like to have and have thought about it a little. A potential approach is to use a special comment for this: import numpy # mypy: ignore We could also support an if statement for this (this actually partially implemented already but completely undocumented): from typing import MYPY
if not MYPY:
import numpy The value of Or maybe we can support using a comment to ignore multiple lines: # mypy: begin ignore
import numpy
import matplotlib.pyplot
import scipy.stats
# mypy: end ignore Implementation of #486 would be awesome but it does not help when there are C extension modules. However, we may be able to automatically generate pure dynamically typed stubs for C extension modules automatically. @ashleyh started writing a stub generator (I have a clone at https://github.com/JukkaL/mypy-stubgen) but there hasn't been updates in a long time. |
I like annotations to instruct mypy to ignore something much more than having to change code by adding |
PEP 484 uses |
Okay, now you can use
|
* Add a bulb * Delete unneeded import and switch from absolute to relative import * Fire request on selection modified, on TextCommand and after Did Change event Request needs to be send on selection modified, to determine whether to show the bulb or not by the caret position. The request needs to be send when the TextCommand is run, because the command might be triggered from the phantom (error|warning|hint) pop-up and when it is triggered the caret might already be on a place where code action exist, so the mouse will trigger those code actions instead of the ones that were suppose to be triggered from the popup. And finally the request needs to be send after the `textDocument/didChange`. So the code actions show suggestions for the current version of document and not for an outdated one. * Introduce cache Code actions get cached on each request, so when running the TextCommand the menu will be populated my cache. However, hovers for warning, errors, hint can run the code action text command. In that case we need to fire a new request, by passing a flag `make_request`, so the code actions that will be displayed are related to the point from where the hover was triggered. * Fix formating * add icons * format import * Don't show the command in the right click menu, when 0 code actions This is different from is_enabled because I don't want to disable the command from running, so the user get the `no code actions` popup * Fix formating * Remove return type * Ignore type, python/mypy#500 (comment) Don't know how to typehint debounce.t * return None for __init__ * leave hover unchanged * Remove cache and event listener, Add a command to update code actions * Need to be at least 500ms To avoid messages in status bar like `Request textDocument/codeAction failed with message. Debug failure. Expected 80 <= 50` * Don't fire command in windows.py file Instead, listen in code_actions.py on_modified_async. An explanation. The following will explain why we need to listen on changes? Short Explanation So we don't end up with a bulb in the gutter when there are no code actions. Long (Detailed) explanation 1. When on_modified_async is fired, on_selection_modified_async is fired as well. 2. When inserting text, I need to make sure that textDocument/codeAction is fired after textDocument/didChange Because of this line in windows.py, notice the 0.5s delay. ```python self._sublime.set_timeout_async(lambda: self.purge_did_change(buffer_id, buffer_version), 500) ``` source: https://github.com/tomv564/LSP/blob/41eba6ef3ca1db9fb2ab4f3b393afe4e376b4c40/plugin/core/windows.py#L256 That is the reason the handle_modified_async fire_requsest has a debounce of 0.8s, 0.3s after from textDocument/didChange. 3. If handle_modified_async is fired, it will debounce fire_request call for another 0.3s (0.8s of handle_modified_async - 0.5s of fire_request) It is needed to check if the code actions are valid after we made some changes. So we don't end up with a bulb in the gutter when there are no code actions * Add a flag * Leave windows.py unchanged * Rename show_bulb to show_code_actions_bulb * Hide bulb when on_selection_modified_async is fired and remove on_modified_async listener. For that change I needed to increase the debounce for fire_request from 0.5 to 0.8 (). Removed LspUpdateCodeActionsCommand, no need for it Pros: Simpler code, with not so noticeable changes for the user Cons: Fires 300ms slower for on_selection_modified_async, that it used to do, but not so noticeable as said * Reintroduce on_modified_async, because of a better user experience * Revert "Reintroduce on_modified_async, because of a better user experience" This reverts commit ccef8b7.
If the expression being ignored is spread out across lines, the ignore annotation doesn't work.
|
This is supported only on Python 3.8, on older versions you need to place the |
It would be nice to ignore code blocks like this, because with use of black it gets difficult to correctly place single def some_func(long_argument_name, another_long_argument_name) -> None: # type: ignore
pass Now run black to format this code: def some_func(
long_argument_name,
another_long_argument_name
) -> None: # type: ignore
pass black has moved # type: begin ignore
def some_func(
long_argument_name,
another_long_argument_name
) -> None:
# type: end ignore
print("Now code formatter can't break my shitty code anymore!") |
@and-semakin this can also be resolved if like the pylint: disable directive you can just put a line comment by itself the line before to ignore the next line. Less likely to cause havoc than an open/close type semantics. What happens if someone moves some code or deletes the end ignore? etc. |
Turns out multi-line ignores aren't a thing until Python 3.8 [1]. I've no idea how this was passing beforehand. The fix is easy - change the order of the args, allowing us to place things where they need to go. [1] python/mypy#500 (comment) Signed-off-by: Stephen Finucane <[email protected]>
I think in general (or at least some cases) it is better to explicitly specify the error code that one wants to ignore by |
Yes, warnings need to be blocked out. I have very strict type checking but ironically mypy just hates pydantic. I can't ignore the line because the auto-formatter in VSCode keeps on putting the ignore comment on the wrong line. I mean, why can't a feature like block disable or whole file ignore for a specific warning type be implemented? At this point my only resolution is to put a This granularity just sucks. It's either per line or the entire file. pylint and flake8 allow disabling whole file warnings/errors, mypy should just do the same thing everyone else is doing. |
I don't know if this is intentionally omitted, or if I'm just not aware of the functionality, but is there any way to ignore mypy errors line-by-line?
For instance, one of the files I'm using mypy on works, but for certain lines...
...mypy gives errors incorrectly that I'd like to ignore (the modules do exist, and max does take the 'key' argument).
Is there any way to skip these lines, such as in a linter, or a way to hint to mypy that these are valid?
The text was updated successfully, but these errors were encountered: