mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-24 02:24:55 +00:00
Use collections ABCs to be safe
This commit is contained in:
parent
97dc802ee6
commit
d09b348d96
1 changed files with 7 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue