-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Plugin hook to selectively silence error messages #7468
Comments
I am quite sure there was a very similar feature request but can't find it. I think a better idea is to add a plugin hook to selectively suppress some error codes (now that we have them) on a given line. Otherwise it sounds too niche. |
Yes, I agree that this is a special case of "there is this error that I know I want to ignore". For this a plugin that gets called at the very end, when everything else is done, would be very useful. Is there already a way to filter out error messages/error codes in the plugin hooks that are already available? |
Well, technically I can't say no, because I would be lying, but I really think you should not do this, better wait for the public API. The error manager is exposed though private type checker API |
Even if this were not fragile (at the moment), I wonder to which symbol one would attach such a plugin to, |
@SaschaSchlemmer |
@ilevkivskyi As discussed in the pull request about ignoring errors by regex, I would like to help you with improving the plugin system, so errors could be ignored from a plugin. First I need to get more familiar with the plugin system of mypy. I will learn more about it in the next days. However my current idea would be to add a hook, which is called every time when an error should reported. This hook can than decide, if the error should be ignored or not. However, this would mean to introduce a new hook and to make the class of the Thanks for your assistance here, |
Should this have the label |
For developing an Either-like monad that types correctly and also behaves nicely at runtime I currently use the following pattern to independently declare the types for mypy and the runtime implementation
During static analysis it is important that
Left
andRight
get treated as aliases forEither
so that assignments get typechecked correctly (even though at runtime they are subclasses (and thus subtypes) ofEither
). Additionally I'd like to be able and useisinstance
checks at runtime to determine whether a result is an instance ofLeft
orRight
(or more general if something is an instance ofEither
). This mostly works (assignments typecheck and runtime behavior is as excepted), however mypy (rightfully) complains about theisinstance
checks thatIn cases like these it would be useful if one could tell mypy that a generic class can be used with instance checks. This would also be somewhat similar to how one can declare protocol classes to support runtime instance checks with the
@runtime_checkable
decorator.This would also allow user defined generics to behave similar to types from typing like
List
wherevs
I'd propose that
@runtime_checkable
marks anGeneric
accordingly so that in the example it would beAddendum
The issue is actually not with
Either
per se but rather with the type aliasesLeft
andRight
. For mypyactually is
I still think this would be a useful feature to be able and better support the dynamic nature of Python with the
if TYPE_CHECKING
pattern.The text was updated successfully, but these errors were encountered: