From db9837fa240918fa90f2d9a3952314bd3207ed20 Mon Sep 17 00:00:00 2001 From: bzoracler <50305397+bzoracler@users.noreply.github.com> Date: Wed, 24 Jul 2024 20:10:42 +1200 Subject: [PATCH] fix: Mismatched signature between checker plugin API and implementation (#17343) This PR changes the `fail` method's signature to be positional-only for the first two parameters, due to a mismatch between the [`CheckerPluginInterface` signature](https://github.com/python/mypy/blob/8dd268ffd84ccf549b3aa9105dd35766a899b2bd/mypy/plugin.py#L242-L244) and the implementation class ([`TypeChecker`](https://github.com/python/mypy/blob/8dd268ffd84ccf549b3aa9105dd35766a899b2bd/mypy/checker.py#L7116-L7118)). ```python class CheckerPluginInterface: ... @abstractmethod def fail( self, msg: str | ErrorMessage, ctx: Context, *, code: ErrorCode | None = None ) -> None: ... ``` ```python class TypeChecker(NodeVisitor[None], CheckerPluginInterface): ... def fail( self, msg: str | ErrorMessage, context: Context, *, code: ErrorCode | None = None ) -> None: ``` An alternative fix would be to change `TypeChecker.fail`'s parameter name to `ctx`, but that has a greater disruption potential. Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- mypy/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/plugin.py b/mypy/plugin.py index 858795addb7f..a1af7fa76350 100644 --- a/mypy/plugin.py +++ b/mypy/plugin.py @@ -240,7 +240,7 @@ def type_context(self) -> list[Type | None]: @abstractmethod def fail( - self, msg: str | ErrorMessage, ctx: Context, *, code: ErrorCode | None = None + self, msg: str | ErrorMessage, ctx: Context, /, *, code: ErrorCode | None = None ) -> None: """Emit an error message at given location.""" raise NotImplementedError