Path 1: 827 calls (1.0)

1 (152) dict (64) 2 (54) list (38) 0 (30) None (28) 'Hello World' (22) Layout (18) 'foo' (18) 3 (18)

False (807) True (20)

1def _is_namedtuple(obj: Any) -> bool:
2    """Checks if an object is most likely a namedtuple. It is possible
3    to craft an object that passes this check and isn't a namedtuple, but
4    there is only a minuscule chance of this happening unintentionally.
5
6    Args:
7        obj (Any): The object to test
8
9    Returns:
10        bool: True if the object is a namedtuple. False otherwise.
11    """
12    try:
13        fields = getattr(obj, "_fields", None)
14    except Exception:
15        # Being very defensive - if we cannot get the attr then its not a namedtuple
16        return False
17    return isinstance(obj, tuple) and isinstance(fields, tuple)
            

Path 2: 2 calls (0.0)

test_broken_getattr..BrokenAttr (2)

False (2)

ZeroDivisionError (2)

1def _is_namedtuple(obj: Any) -> bool:
2    """Checks if an object is most likely a namedtuple. It is possible
3    to craft an object that passes this check and isn't a namedtuple, but
4    there is only a minuscule chance of this happening unintentionally.
5
6    Args:
7        obj (Any): The object to test
8
9    Returns:
10        bool: True if the object is a namedtuple. False otherwise.
11    """
12    try:
13        fields = getattr(obj, "_fields", None)
14    except Exception:
15        # Being very defensive - if we cannot get the attr then its not a namedtuple
16        return False
17    return isinstance(obj, tuple) and isinstance(fields, tuple)