Skip to content

Commit 4041c2e

Browse files
dizczaJackUrb
authored andcommitted
check types with isinstance; allow tuple, where possible
1 parent 458cced commit 4041c2e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

py/visdom/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _title2str(opts):
140140

141141

142142
def _scrub_dict(d):
143-
if type(d) is dict:
143+
if isinstance(d, dict):
144144
return {k: _scrub_dict(v) for k, v in list(d.items())
145145
if v is not None and _scrub_dict(v) is not None}
146146
else:
@@ -1561,9 +1561,10 @@ def scatter(self, X, Y=None, win=None, env=None, opts=None, update=None,
15611561
_assert_opts(opts)
15621562

15631563
if opts.get('legend'):
1564-
assert type(opts['legend']) == list and K <= len(opts['legend']), \
1565-
'largest label should not be greater than size of the ' \
1566-
'legends table'
1564+
assert isinstance(opts['legend'], (tuple, list)) \
1565+
and K <= len(opts['legend']), \
1566+
'largest label should not be greater than size of ' \
1567+
'the legends table'
15671568

15681569
data = []
15691570
trace_opts = opts.get('traceopts', {'plotly': {}})['plotly']

py/visdom/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def get_messages(self):
407407
to_send = []
408408
while len(self.messages) > 0:
409409
message = self.messages.pop()
410-
if type(message) is dict:
410+
if isinstance(message, dict):
411411
# Not all messages are being formatted the same way (JSON)
412412
# TODO investigate
413413
message = json.dumps(message)
@@ -656,7 +656,7 @@ def get_messages(self):
656656
to_send = []
657657
while len(self.messages) > 0:
658658
message = self.messages.pop()
659-
if type(message) is dict:
659+
if isinstance(message, dict):
660660
# Not all messages are being formatted the same way (JSON)
661661
# TODO investigate
662662
message = json.dumps(message)
@@ -769,7 +769,7 @@ def window(args):
769769

770770
def broadcast(self, msg, eid):
771771
for s in self.subs:
772-
if type(self.subs[s].eid) is list:
772+
if isinstance(self.subs[s].eid, dict):
773773
if eid in self.subs[s].eid:
774774
self.subs[s].write_message(msg)
775775
else:

0 commit comments

Comments
 (0)