@@ -670,7 +670,7 @@ def _verify_arg_default_value(
670
670
stub_arg : nodes .Argument , runtime_arg : inspect .Parameter
671
671
) -> Iterator [str ]:
672
672
"""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 :
674
674
if stub_arg .kind .is_required ():
675
675
yield (
676
676
f'runtime argument "{ runtime_arg .name } " '
@@ -705,18 +705,26 @@ def _verify_arg_default_value(
705
705
stub_default is not UNKNOWN
706
706
and stub_default is not ...
707
707
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
- )
714
708
):
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
+ defaults_match = True
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
+ defaults_match = False
714
+ else :
715
+ try :
716
+ defaults_match = bool (stub_default == runtime_arg .default )
717
+ except Exception :
718
+ # Exception can be raised in bool dunder method (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
+ defaults_match = False
722
+ if not defaults_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
+ )
720
728
else :
721
729
if stub_arg .kind .is_optional ():
722
730
yield (
@@ -758,7 +766,7 @@ def get_type(arg: Any) -> str | None:
758
766
759
767
def has_default (arg : Any ) -> bool :
760
768
if isinstance (arg , inspect .Parameter ):
761
- return bool ( arg .default != inspect .Parameter .empty )
769
+ return arg .default is not inspect .Parameter .empty
762
770
if isinstance (arg , nodes .Argument ):
763
771
return arg .kind .is_optional ()
764
772
raise AssertionError
@@ -1628,13 +1636,13 @@ def anytype() -> mypy.types.AnyType:
1628
1636
arg_names .append (
1629
1637
None if arg .kind == inspect .Parameter .POSITIONAL_ONLY else arg .name
1630
1638
)
1631
- has_default = arg .default == inspect .Parameter .empty
1639
+ no_default = arg .default is inspect .Parameter .empty
1632
1640
if arg .kind == inspect .Parameter .POSITIONAL_ONLY :
1633
- arg_kinds .append (nodes .ARG_POS if has_default else nodes .ARG_OPT )
1641
+ arg_kinds .append (nodes .ARG_POS if no_default else nodes .ARG_OPT )
1634
1642
elif arg .kind == inspect .Parameter .POSITIONAL_OR_KEYWORD :
1635
- arg_kinds .append (nodes .ARG_POS if has_default else nodes .ARG_OPT )
1643
+ arg_kinds .append (nodes .ARG_POS if no_default else nodes .ARG_OPT )
1636
1644
elif arg .kind == inspect .Parameter .KEYWORD_ONLY :
1637
- arg_kinds .append (nodes .ARG_NAMED if has_default else nodes .ARG_NAMED_OPT )
1645
+ arg_kinds .append (nodes .ARG_NAMED if no_default else nodes .ARG_NAMED_OPT )
1638
1646
elif arg .kind == inspect .Parameter .VAR_POSITIONAL :
1639
1647
arg_kinds .append (nodes .ARG_STAR )
1640
1648
elif arg .kind == inspect .Parameter .VAR_KEYWORD :
0 commit comments