MCPcopy Index your code
hub / github.com/python/mypy / _verify_arg_name

Function _verify_arg_name

mypy/stubtest.py:794–828  ·  view source on GitHub ↗

Checks whether argument names match.

(
    stub_arg: nodes.Argument, runtime_arg: inspect.Parameter, function_name: str
)

Source from the content-addressed store, hash-verified

792
793
794def _verify_arg_name(
795 stub_arg: nodes.Argument, runtime_arg: inspect.Parameter, function_name: str
796) -> Iterator[str]:
797 """Checks whether argument names match."""
798 # Ignore exact names for most dunder methods
799 if is_dunder(function_name, exclude_special=True):
800 return
801
802 if (
803 stub_arg.variable.name == runtime_arg.name
804 or stub_arg.variable.name.removeprefix("__") == runtime_arg.name
805 ):
806 return
807
808 nonspecific_names = {"object", "args"}
809 if runtime_arg.name in nonspecific_names:
810 return
811
812 def names_approx_match(a: str, b: str) -> bool:
813 a = a.strip("_")
814 b = b.strip("_")
815 return a.startswith(b) or b.startswith(a) or len(a) == 1 or len(b) == 1
816
817 # Be more permissive about names matching for positional-only arguments
818 if runtime_arg.kind == inspect.Parameter.POSITIONAL_ONLY and names_approx_match(
819 stub_arg.variable.name, runtime_arg.name
820 ):
821 return
822 # This comes up with namedtuples, so ignore
823 if stub_arg.variable.name == "_self":
824 return
825 yield (
826 f'stub parameter "{stub_arg.variable.name}" '
827 f'differs from runtime parameter "{runtime_arg.name}"'
828 )
829
830
831def _verify_arg_default_value(

Callers 1

_verify_signatureFunction · 0.85

Calls 3

is_dunderFunction · 0.90
names_approx_matchFunction · 0.85
removeprefixMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…