Skip to content

Commit

Permalink
Account for _SpecialForm
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 8, 2024
1 parent 12ead71 commit 6481da5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
12 changes: 11 additions & 1 deletion pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 13 additions & 12 deletions tests/functional/u/used/used_before_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6481da5

Please sign in to comment.