Repository navigation
Plugin hook to selectively silence error messages #7468
Description
Activity
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.
- addedtopic-pluginsThe plugin API and ideas for new pluginsThe plugin API and ideas for new plugins
on Sep 5, 2019 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
ctx.api.msg.errorsbut trying to do something there is super-fragile.Even if this were not fragile (at the moment), I wonder to which symbol one would attach such a plugin to,
isinstanceorEither?@SaschaSchlemmer
get_function_hook()forisinstance(). But this is the last thing I say here :-)- changed the title
[-]instance checks of parameterized generics[/-][+]Plugin hook to selectively silence error messages[/+]on Sep 12, 2019 @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.
For this the hook would need theinfoobject of the error, which holds many useful information to do this decision.However, this would mean to introduce a new hook and to make the class of the
infoobject public for plugins. When I understand your discussion in this thread correctly, both are think you normally avoid, right? Do you have another approach in mind?Thanks for your assistance here,
AndréShould this have the label
topic-pep-604? This seems like it might given other open issues with that 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
LeftandRightget treated as aliases forEitherso that assignments get typechecked correctly (even though at runtime they are subclasses (and thus subtypes) ofEither). Additionally I'd like to be able and useisinstancechecks at runtime to determine whether a result is an instance ofLeftorRight(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 theisinstancechecks 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_checkabledecorator.This would also allow user defined generics to behave similar to types from typing like
Listwherevs
I'd propose that
@runtime_checkablemarks anGenericaccordingly so that in the example it would beAddendum
The issue is actually not with
Eitherper se but rather with the type aliasesLeftandRight. 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_CHECKINGpattern.