-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash with custom ErrorCodes (#15327)
A class marked with `allow_interpreted_subclasses=True` implicitly supports serialization while also allowing it to be subclassed by pure Python code. Fixes #15255 https://mypyc.readthedocs.io/en/latest/differences_from_python.html#pickling-and-copying-objects https://mypyc.readthedocs.io/en/latest/native_classes.html#inheritance
- Loading branch information
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from mypy.errorcodes import ErrorCode | ||
from mypy.plugin import Plugin | ||
from mypy.types import AnyType, TypeOfAny | ||
|
||
CUSTOM_ERROR = ErrorCode(code="custom", description="", category="Custom") | ||
|
||
|
||
class CustomErrorCodePlugin(Plugin): | ||
def get_function_hook(self, fullname): | ||
if fullname.endswith(".main"): | ||
return self.emit_error | ||
return None | ||
|
||
def emit_error(self, ctx): | ||
ctx.api.fail("Custom error", ctx.context, code=CUSTOM_ERROR) | ||
return AnyType(TypeOfAny.from_error) | ||
|
||
|
||
def plugin(version): | ||
return CustomErrorCodePlugin |