@@ -670,7 +670,7 @@ def _verify_arg_default_value(
670670 stub_arg : nodes .Argument , runtime_arg : inspect .Parameter
671671) -> Iterator [str ]:
672672 """Checks whether argument default values are compatible."""
673- if runtime_arg .default != inspect .Parameter .empty :
673+ if runtime_arg .default is not inspect .Parameter .empty :
674674 if stub_arg .kind .is_required ():
675675 yield (
676676 f'runtime argument "{ runtime_arg .name } " '
@@ -705,18 +705,26 @@ def _verify_arg_default_value(
705705 stub_default is not UNKNOWN
706706 and stub_default is not ...
707707 and runtime_arg .default is not UNREPRESENTABLE
708- and (
709- stub_default != runtime_arg .default
710- # We want the types to match exactly, e.g. in case the stub has
711- # True and the runtime has 1 (or vice versa).
712- or type (stub_default ) is not type (runtime_arg .default )
713- )
714708 ):
715- yield (
716- f'runtime argument "{ runtime_arg .name } " '
717- f"has a default value of { runtime_arg .default !r} , "
718- f"which is different from stub argument default { stub_default !r} "
719- )
709+ no_match = False
710+ # We want the types to match exactly, e.g. in case the stub has
711+ # True and the runtime has 1 (or vice versa).
712+ if type (stub_default ) is not type (runtime_arg .default ):
713+ no_match = True
714+ else :
715+ try :
716+ no_match = bool (stub_default != runtime_arg .default )
717+ except Exception :
718+ # Exception can be raised in eq/ne dunder methods (e.g. numpy arrays)
719+ # At this point, consider the default to be different, it is probably
720+ # too complex to put in a stub anyway.
721+ no_match = True
722+ if no_match :
723+ yield (
724+ f'runtime argument "{ runtime_arg .name } " '
725+ f"has a default value of { runtime_arg .default !r} , "
726+ f"which is different from stub argument default { stub_default !r} "
727+ )
720728 else :
721729 if stub_arg .kind .is_optional ():
722730 yield (
@@ -758,7 +766,7 @@ def get_type(arg: Any) -> str | None:
758766
759767 def has_default (arg : Any ) -> bool :
760768 if isinstance (arg , inspect .Parameter ):
761- return bool ( arg .default != inspect .Parameter .empty )
769+ return arg .default is not inspect .Parameter .empty
762770 if isinstance (arg , nodes .Argument ):
763771 return arg .kind .is_optional ()
764772 raise AssertionError
@@ -1628,7 +1636,7 @@ def anytype() -> mypy.types.AnyType:
16281636 arg_names .append (
16291637 None if arg .kind == inspect .Parameter .POSITIONAL_ONLY else arg .name
16301638 )
1631- has_default = arg .default == inspect .Parameter .empty
1639+ has_default = arg .default is inspect .Parameter .empty
16321640 if arg .kind == inspect .Parameter .POSITIONAL_ONLY :
16331641 arg_kinds .append (nodes .ARG_POS if has_default else nodes .ARG_OPT )
16341642 elif arg .kind == inspect .Parameter .POSITIONAL_OR_KEYWORD :
0 commit comments