-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
False positive when NoReturn is annotated using a text annotation #6815
Comments
@NeilGirdhar Where are you suppressing |
@DanielNoord Sorrry I meant
My mistake. |
Since this is related to Those are community maintained extensions for pylint which offer support for pytest. Pylint itself doesn't offer this. |
@DanielNoord I'm not using either of those extensions. Isn't pylint just using its own analysis to evaluate this error? |
Yes, but for some external packages we need to rely on some hints to make sure we understand the packages correctly. However, we can't do this for all packages, as we are also limited in our maintainers' time. That's why some external packages are supported through community plugins, like |
I understand, but isn't the type annotation enough? I'll try to construct a MWE later tonight. My guess is that pylint isn't preserving the Incidentally, thanks for teaching me about pylint-pytest. That looks really useful to me! |
Here's an example that doesn't use pytest: from typing import Any, Callable, Protocol, Type, TypeVar, cast
_F = TypeVar("_F", bound=Callable[..., object])
_ET = TypeVar("_ET", bound=Type[BaseException])
class _WithException(Protocol[_F, _ET]):
Exception: _ET
__call__: _F
def _with_exception(exception_type: _ET) -> Callable[[_F], _WithException[_F, _ET]]:
def decorate(func: _F) -> _WithException[_F, _ET]:
func_with_exception = cast(_WithException[_F, _ET], func)
func_with_exception.Exception = exception_type
return func_with_exception
return decorate
@_with_exception(BaseException)
def skip(reason: str = "") -> "NoReturn":
print(reason)
def distribution_info(request: Any):
if request is not None: # dummy condition
return None
skip("Deselected") @DanielNoord Is this something that's worth fixing? |
This is not a false positive, the issue here is that the return are inconsistent in the function. I.e. from typing import Any
import pytest
def distribution_info(request: Any):
if request is not None: # dummy condition
return request.param
return pytest.skip("Deselected {info_name}") |
@Pierre-Sassoulas I believe you're mistaken. One fix that does work is changing the annotation in Pytest from If you plan on supporting text annotations, then please reopen the issue. |
Well adding a return is easier to understand for both human and linter imo, it's just a clue that it's going to "return" without having to check what skip does so you just have to read the function to understand it easily. If you think this check and the fix it currently require does not make sense you can disable it. We have an issue for taking typing into account #4813, it's not going to be in pylint before a long time. pylint is not mypy, mypy has 2k+ open issues, and pylint has it's own issues to take care off. |
I understand what you're saying, but if you really need to remind the reader, then I think a comment would be better. Writing code that never runs is confusing.
Fair enough! Let's leave this closed then as low priority, and hopefully Pytest accepts my pull request, which will resolve this issue for me. |
Bug description
Produces
even though
pytest.skip
is markedNoReturn
.Pylint version
The text was updated successfully, but these errors were encountered: