diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index f3798785531..019bc7a2936 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -2169,12 +2169,22 @@ def is_terminating_func(node: nodes.Call) -> bool: and inferred.qname() in TERMINATING_FUNCS_QNAMES ): return True + # Unwrap to get the actual function node object + if isinstance(inferred, astroid.BoundMethod) and isinstance( + inferred._proxied, astroid.UnboundMethod + ): + inferred = inferred._proxied._proxied if ( isinstance(inferred, nodes.FunctionDef) and isinstance(inferred.returns, nodes.Name) and (inferred_func := safe_infer(inferred.returns)) and hasattr(inferred_func, "qname") - and inferred_func.qname() in TYPING_NORETURN + and inferred_func.qname() + in ( + *TYPING_NORETURN, + # In Python 3.7 - 3.8, NoReturn is alias of '_SpecialForm' + "typing._SpecialForm", + ) ): return True except (StopIteration, astroid.InferenceError): diff --git a/tests/functional/u/used/used_before_assignment.py b/tests/functional/u/used/used_before_assignment.py index 372e641d2af..37da03d7e5a 100644 --- a/tests/functional/u/used/used_before_assignment.py +++ b/tests/functional/u/used/used_before_assignment.py @@ -208,16 +208,17 @@ def inner_if_continues_outer_if_has_no_other_statements(): print(order) -def skip(msg) -> NoReturn: - raise Exception(msg) # pylint: disable=broad-exception-raised - - -def print_platform_specific_command(): - if sys.platform == "linux": - cmd = "ls" - elif sys.platform == "win32": - cmd = "dir" - else: - skip("only runs on Linux/Windows") +class PlatformChecks: + """https://github.com/pylint-dev/pylint/issues/9674""" + def skip(self, msg) -> NoReturn: + raise Exception(msg) # pylint: disable=broad-exception-raised + + def print_platform_specific_command(self): + if sys.platform == "linux": + cmd = "ls" + elif sys.platform == "win32": + cmd = "dir" + else: + self.skip("only runs on Linux/Windows") - print(cmd) + print(cmd)