Skip to content
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

Handle assert_never() when imported from typing_extensions (#9782) #9790

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9780.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Treat `assert_never()` the same way when imported from `typing_extensions`.

Closes #9780
5 changes: 2 additions & 3 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
is_sys_guard,
overridden_method,
)
from pylint.constants import PY39_PLUS, PY311_PLUS, TYPING_NEVER, TYPING_NORETURN
from pylint.constants import PY39_PLUS, TYPING_NEVER, TYPING_NORETURN
from pylint.interfaces import CONTROL_FLOW, HIGH, INFERENCE, INFERENCE_FAILURE
from pylint.typing import MessageDefinitionTuple

Expand Down Expand Up @@ -944,8 +944,7 @@ def _defines_name_raises_or_returns(name: str, node: nodes.NodeNG) -> bool:
if utils.is_terminating_func(node.value):
return True
if (
PY311_PLUS
and isinstance(node.value.func, nodes.Name)
isinstance(node.value.func, nodes.Name)
and node.value.func.name == "assert_never"
):
return True
Expand Down
8 changes: 7 additions & 1 deletion tests/functional/u/used/used_before_assignment_py311.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""assert_never() introduced in 3.11"""
from enum import Enum
from typing import assert_never

from pylint.constants import PY311_PLUS

if PY311_PLUS:
from typing import assert_never # pylint: disable=no-name-in-module
else:
from typing_extensions import assert_never


class MyEnum(Enum):
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/u/used/used_before_assignment_py311.rc

This file was deleted.

Loading