Skip to content
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/8067.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed a crash when inferring a value and using its qname on a slice that was being incorrectly called.

Closes #8067
5 changes: 4 additions & 1 deletion pylint/checkers/method_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from typing import TYPE_CHECKING

from astroid import arguments, nodes
from astroid import arguments, bases, nodes

from pylint.checkers import BaseChecker, utils
from pylint.interfaces import INFERENCE
Expand Down Expand Up @@ -69,6 +69,9 @@ def visit_call(self, node: nodes.Call) -> None:
if (
inferred
and not call_site.has_invalid_keywords()
and isinstance(
inferred, (nodes.FunctionDef, nodes.ClassDef, bases.UnboundMethod)
)
and inferred.qname() in self.linter.config.timeout_methods
):
keyword_arguments = [keyword.arg for keyword in node.keywords]
Expand Down
6 changes: 4 additions & 2 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,9 @@ def _check_consider_using_with(self, node: nodes.Call) -> None:
# the result of this call was already assigned to a variable and will be checked when leaving the scope.
return
inferred = utils.safe_infer(node.func)
if not inferred:
if not inferred or not isinstance(
inferred, (nodes.FunctionDef, nodes.ClassDef, bases.UnboundMethod)
):
return
could_be_used_in_with = (
# things like ``lock.acquire()``
Expand Down Expand Up @@ -1998,7 +2000,7 @@ def _is_function_def_never_returning(self, node: nodes.FunctionDef) -> bool:
)
try:
return node.qname() in self._never_returning_functions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly node is typed incorrectly, but oh well πŸ˜„

except TypeError:
except (TypeError, AttributeError):
return False

def _check_return_at_the_end(self, node: nodes.FunctionDef) -> None:
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/r/regression_02/regression_8067.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Regression tests for inferred.qname missing"""

# pylint: disable=missing-docstring,too-few-public-methods,disallowed-name

x = slice(42)
x() # [not-callable]


class Foo:
def __init__(self, foo=slice(42)):
self.foo = foo


def bar():
i = Foo()
i.foo()
return 100
1 change: 1 addition & 0 deletions tests/functional/r/regression_02/regression_8067.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not-callable:6:0:6:3::x is not callable:UNDEFINED