Checks whether argument names match.
(
stub_arg: nodes.Argument, runtime_arg: inspect.Parameter, function_name: str
)
| 792 | |
| 793 | |
| 794 | def _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 | |
| 831 | def _verify_arg_default_value( |
no test coverage detected
searching dependent graphs…