Skip to content

Commit

Permalink
Handle assert_never() when imported from typing_extensions (#9782)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Jul 12, 2024
1 parent dd20b30 commit a48cd4c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
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 PY311_PLUS, TYPING_NEVER, TYPING_NORETURN
from pylint.constants import 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.

0 comments on commit a48cd4c

Please sign in to comment.