Skip to content

Commit

Permalink
Add debug print junk to help understand code, to be removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Jan 17, 2025
1 parent 2735022 commit 32e950e
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,45 +1453,69 @@ def visit_call(self, node: nodes.Call) -> None:
"""Check that called functions/methods are inferred to callable objects,
and that passed arguments match the parameters in the inferred function.
"""
called = safe_infer(node.func, compare_constructors=True)
def _dp(s, val = None):
if val is None:
print(f" {s}", flush=True)
else:
print(f" {s}: {val}", flush=True)
_dp("-" * 25)
_dp("visit call, node", node)

called = safe_infer(node.func, compare_constructors=True)
_dp("a")
self._check_not_callable(node, called)

_dp("b")
try:
_dp("c")
called, implicit_args, callable_name = _determine_callable(called)
_dp("d")
except ValueError:
# Any error occurred during determining the function type, most of
# those errors are handled by different warnings.
_dp("e")
return

_dp("f")
if called.args.args is None:
_dp("g")
if called.name == "isinstance":
# Verify whether second argument of isinstance is a valid type
_dp("h")
self._check_isinstance_args(node, callable_name)
# Built-in functions have no argument information.
_dp("i")
return

_dp("j")
if len(called.argnames()) != len(set(called.argnames())):
# Duplicate parameter name (see duplicate-argument). We can't really
# make sense of the function call in this case, so just return.
_dp("k")
return

# Build the set of keyword arguments, checking for duplicate keywords,
# and count the positional arguments.
_dp("L")
call_site = astroid.arguments.CallSite.from_call(node)

# Warn about duplicated keyword arguments, such as `f=24, **{'f': 24}`
_dp("m")
for keyword in call_site.duplicated_keywords:
_dp("N")
self.add_message("repeated-keyword", node=node, args=(keyword,))

_dp("O")
if call_site.has_invalid_arguments() or call_site.has_invalid_keywords():
# Can't make sense of this.
_dp("p")
return

# Has the function signature changed in ways we cannot reliably detect?
_dp("q")
if hasattr(called, "decorators") and decorated_with(
called, self.linter.config.signature_mutators
):
_dp("R")
return

num_positional_args = len(call_site.positional_arguments)
Expand Down Expand Up @@ -1523,14 +1547,25 @@ def visit_call(self, node: nodes.Call) -> None:
# inside the class where the function is defined.
# This avoids emitting `too-many-function-args` since `num_positional_args`
# includes an implicit `self` argument which is not present in `called.args`.
_dp("NOTE: about to dec")
_dp("node frame", node.frame())
_dp("isinst", isinstance(node.frame(), nodes.ClassDef))
_dp("funcdef", isinstance(called, nodes.FunctionDef))
_dp("called", called)
_dp("frame body", node.frame().body)
_dp("called in frame body", called in node.frame().body)
_dp("npa", num_positional_args)
_dp("dec names", called.decoratornames())
if (
isinstance(node.frame(), nodes.ClassDef)
and isinstance(called, nodes.FunctionDef)
and called in node.frame().body
and num_positional_args > 0
and "builtins.staticmethod" not in called.decoratornames()
):
_dp("NOTE: decrementing")
num_positional_args -= 1
_dp("NOTE: dec done")

# Analyze the list of formal parameters.
args = list(itertools.chain(called.args.posonlyargs or (), called.args.args))
Expand Down

0 comments on commit 32e950e

Please sign in to comment.