-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typing_extensions assert_never's Never not supported #7565
Comments
I'd like to point out that this is still a bug in pylint, which is quite annoying when you use In addition, handling |
Do you want to open a PR with the patch @svenpanne ?
This is not the case right now, see #4813. Changing that will be quite a journey
What configuration options are we talking about ? |
It's basically the patch above, let's see when I find some time...
Actually pylint already figures out enough, verified by
https://pylint.readthedocs.io/en/latest/user_guide/configuration/all-options.html#never-returning-functions My point is: If the user explicitly configures that some functions never return, this should override any logic in pylint, so the order of tests in the function above should be reversed. If this was the case, adding So in effect, there are 2 bugs in the method. |
Repro for the second issue @svenpanne describes:
# pylint: disable=missing-function-docstring,missing-module-docstring
from __future__ import annotations
from typing_extensions import (
assert_never,
Union,
)
def some_func(arg: Union[int, str]) -> int:
if isinstance(arg, int):
return 1
if isinstance(arg, str):
return 2
assert_never(arg)
|
Any update on this? |
This fixes 2 bugs in the computation: * `Never` is handled in addition to `NoReturn`. * Give priority to the explicit `--never-returning-functions` option. Closes pylint-dev#7565
OK, I've uploaded a PR for this, fixing both problems: With this change, things work out-of-the-box for Python 3.11 and 3.12 with both |
This fixes 2 bugs in the computation: * `Never` is handled in addition to `NoReturn`. * Give priority to the explicit `--never-returning-functions` option. Closes pylint-dev#7565
This fixes 2 bugs in the computation: * `Never` is handled in addition to `NoReturn`. * Give priority to the explicit `--never-returning-functions` option. Closes pylint-dev#7565
This fixes 2 bugs in the computation: * `Never` is handled in addition to `NoReturn`. * Give priority to the explicit `--never-returning-functions` option. Closes pylint-dev#7565
Bug description
Python 3.11 added
Never
as an alias ofNoReturn
. The signature ofassert_never
isassert_never(__x: Never) -> Never
(personally, I wish had beenassert_never(__x: Never) -> NoReturn
, but that's what it is). This was backported totyping_extensions
4.1.0, as well.I tried the following, but it seems
typing_extensions.assert_never
is uninferable.If it's defined locally, however:
Then the above patch fixes it, so there's that, at least. Maybe that would at least fix it on Python 3.11? Maybe
typing_extensions.assert_never
could be added to the list of no return functions if it can't be inferred? However, when I stick an print statement in here, it seems the node is "Uninferrable", and adding"typing_extensions.assert_never"
torefactoring.never-returning-functions
does not work.This is using cibuildwheel's source, see pypa/cibuildwheel#1291.
It looks like this was partially addressed in #7311, but not for all places NoReturn shows up.
Configuration
No response
Command used
Pylint output
Expected behavior
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Pylint version
OS / Environment
No response
Additional dependencies
typing_extensions==4.3.0
The text was updated successfully, but these errors were encountered: