Skip to content

Commit

Permalink
fix: Mismatched signature between checker plugin API and implementati…
Browse files Browse the repository at this point in the history
…on (python#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]>
  • Loading branch information
bzoracler and hauntsaninja committed Jul 24, 2024
1 parent 312694f commit db9837f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db9837f

Please sign in to comment.