Skip to content

Commit db9837f

Browse files
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 <[email protected]>
1 parent 312694f commit db9837f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mypy/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def type_context(self) -> list[Type | None]:
240240

241241
@abstractmethod
242242
def fail(
243-
self, msg: str | ErrorMessage, ctx: Context, *, code: ErrorCode | None = None
243+
self, msg: str | ErrorMessage, ctx: Context, /, *, code: ErrorCode | None = None
244244
) -> None:
245245
"""Emit an error message at given location."""
246246
raise NotImplementedError

0 commit comments

Comments
 (0)