From d09b348d96dc4b53637598a94ca185fc184ca00f Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Mon, 29 Apr 2019 08:54:40 +0200 Subject: [PATCH] Use collections ABCs to be safe --- pysnooper/variables.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pysnooper/variables.py b/pysnooper/variables.py index de9cfd7..00f67f4 100644 --- a/pysnooper/variables.py +++ b/pysnooper/variables.py @@ -1,4 +1,5 @@ import itertools +from collections import Mapping, Sequence from copy import deepcopy from .utils import get_shortish_repr, ensure_tuple @@ -94,16 +95,11 @@ class Indices(Keys): class Exploded(BaseVariable): def _items(self, main_value): - typ = main_value.__class__ - - def has_method(name): - return callable(getattr(typ, name, None)) - - cls = Attrs - if has_method('__getitem__'): - if has_method('keys'): - cls = Keys - elif has_method('__len__'): - cls = Indices + if isinstance(main_value, Mapping): + cls = Keys + elif isinstance(main_value, Sequence): + cls = Indices + else: + cls = Attrs return cls(self.source, self.exclude)._items(main_value)