Skip to content

Commit bd4c8f1

Browse files
Handle assert_never() when imported from typing_extensions (#9782) (#9790)
(cherry picked from commit a48cd4c)
1 parent 8eb2c4d commit bd4c8f1

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Treat `assert_never()` the same way when imported from `typing_extensions`.
2+
3+
Closes #9780

pylint/checkers/variables.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
is_sys_guard,
3333
overridden_method,
3434
)
35-
from pylint.constants import PY39_PLUS, PY311_PLUS, TYPING_NEVER, TYPING_NORETURN
35+
from pylint.constants import PY39_PLUS, TYPING_NEVER, TYPING_NORETURN
3636
from pylint.interfaces import CONTROL_FLOW, HIGH, INFERENCE, INFERENCE_FAILURE
3737
from pylint.typing import MessageDefinitionTuple
3838

@@ -944,8 +944,7 @@ def _defines_name_raises_or_returns(name: str, node: nodes.NodeNG) -> bool:
944944
if utils.is_terminating_func(node.value):
945945
return True
946946
if (
947-
PY311_PLUS
948-
and isinstance(node.value.func, nodes.Name)
947+
isinstance(node.value.func, nodes.Name)
949948
and node.value.func.name == "assert_never"
950949
):
951950
return True

tests/functional/u/used/used_before_assignment_py311.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
"""assert_never() introduced in 3.11"""
22
from enum import Enum
3-
from typing import assert_never
3+
4+
from pylint.constants import PY311_PLUS
5+
6+
if PY311_PLUS:
7+
from typing import assert_never # pylint: disable=no-name-in-module
8+
else:
9+
from typing_extensions import assert_never
410

511

612
class MyEnum(Enum):

tests/functional/u/used/used_before_assignment_py311.rc

-2
This file was deleted.

0 commit comments

Comments
 (0)