pylint
pylint copied to clipboard
False positive for `unnecessary-ellipsis` on `Protocol` methods
Bug description
`pyright` uses `...` to determine the body of this method is not implemented here. Without using `...`, `pyright` rightfully (IMHO, as is the only way it has to know the user is intentionally omitting the body) complains about a missing return to match the declared return type of the function.
Example:
"""Module docstring."""
from typing import Protocol
# pylint: disable=too-few-public-methods
class P(Protocol):
"""Class docstring"""
def f(self) -> int:
"""Method docstring"""
...
When removing the `...` pylint passes by `pyright` says:
```console
[test] $ pyright t.py
/tmp/test/t.py
/tmp/test/t.py:10:20 - error: Function with declared return type "int" must return value on all code paths
"None" is incompatible with "int" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations
### Configuration
```ini
None.
Steps to reproduce:
$ python3.11 -m venv test
$ cd test/
$ . bin/activate
[test] $ pip install pylint pyright
Collecting pylint
Using cached pylint-3.0.3-py3-none-any.whl.metadata (12 kB)
Collecting pyright
Using cached pyright-1.1.341-py3-none-any.whl.metadata (6.2 kB)
Collecting platformdirs>=2.2.0 (from pylint)
Using cached platformdirs-4.1.0-py3-none-any.whl.metadata (11 kB)
Collecting astroid<=3.1.0-dev0,>=3.0.1 (from pylint)
Using cached astroid-3.0.2-py3-none-any.whl.metadata (4.5 kB)
Collecting isort!=5.13.0,<6,>=4.2.5 (from pylint)
Using cached isort-5.13.2-py3-none-any.whl.metadata (12 kB)
Collecting mccabe<0.8,>=0.6 (from pylint)
Using cached mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
Collecting tomlkit>=0.10.1 (from pylint)
Using cached tomlkit-0.12.3-py3-none-any.whl.metadata (2.7 kB)
Collecting dill>=0.3.6 (from pylint)
Using cached dill-0.3.7-py3-none-any.whl.metadata (9.9 kB)
Collecting nodeenv>=1.6.0 (from pyright)
Using cached nodeenv-1.8.0-py2.py3-none-any.whl.metadata (21 kB)
Requirement already satisfied: setuptools in ./lib/python3.11/site-packages (from nodeenv>=1.6.0->pyright) (68.1.2)
Using cached pylint-3.0.3-py3-none-any.whl (510 kB)
Using cached pyright-1.1.341-py3-none-any.whl (18 kB)
Using cached astroid-3.0.2-py3-none-any.whl (275 kB)
Using cached dill-0.3.7-py3-none-any.whl (115 kB)
Using cached isort-5.13.2-py3-none-any.whl (92 kB)
Using cached nodeenv-1.8.0-py2.py3-none-any.whl (22 kB)
Using cached platformdirs-4.1.0-py3-none-any.whl (17 kB)
Using cached tomlkit-0.12.3-py3-none-any.whl (37 kB)
Installing collected packages: tomlkit, platformdirs, nodeenv, mccabe, isort, dill, astroid, pyright, pylint
Successfully installed astroid-3.0.2 dill-0.3.7 isort-5.13.2 mccabe-0.7.0 nodeenv-1.8.0 platformdirs-4.1.0 pylint-3.0.3 pyright-1.1.341 tomlkit-0.12.3
Command used
`pylint t.py`
Pylint output
************* Module t
t.py:12:8: W2301: Unnecessary ellipsis constant (unnecessary-ellipsis)
------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 5.00/10, +2.50)
### Expected behavior
No failures.
### Pylint version
```shell
pylint 3.0.3
astroid 3.0.2
Python 3.11.7 (main, Dec 8 2023, 14:22:46) [GCC 13.2.0]
OS / Environment
Debian testing
Additional dependencies
$ pip freeze
astroid==3.0.2
dill==0.3.7
isort==5.13.2
mccabe==0.7.0
nodeenv==1.8.0
platformdirs==4.1.0
pylint==3.0.3
pyright==1.1.341
tomlkit==0.12.3