Skip to content

check types with isinstance; allow tuple, where possible #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions py/visdom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _title2str(opts):


def _scrub_dict(d):
if type(d) is dict:
if isinstance(d, dict):
return {k: _scrub_dict(v) for k, v in list(d.items())
if v is not None and _scrub_dict(v) is not None}
else:
Expand Down Expand Up @@ -1469,7 +1469,7 @@ def scatter(self, X, Y=None, win=None, env=None, opts=None, update=None,
- `opts.markerborderwidth`: marker border line width (`float`; default = 0.5)
- `opts.dash` : dash type (`np.array`; default = 'solid'`)
- `opts.textlabels` : text label for each point (`list`: default = `None`)
- `opts.legend` : `list` containing legend names
- `opts.legend` : `list` or `tuple` containing legend names
"""
if update == 'remove':
assert win is not None
Expand Down Expand Up @@ -1561,9 +1561,10 @@ def scatter(self, X, Y=None, win=None, env=None, opts=None, update=None,
_assert_opts(opts)

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

data = []
trace_opts = opts.get('traceopts', {'plotly': {}})['plotly']
Expand Down Expand Up @@ -1669,7 +1670,7 @@ def line(self, Y, X=None, win=None, env=None, opts=None, update=None,
- `opts.markersize` : marker size (`number`; default = `'10'`)
- `opts.linecolor` : line colors (`np.array`; default = None)
- `opts.dash` : line dash type (`np.array`; default = None)
- `opts.legend` : `list` containing legend names
- `opts.legend` : `list` or `tuple` containing legend names

If `update` is specified, the figure will be updated without
creating a new plot -- this can be used for efficient updating.
Expand Down
6 changes: 3 additions & 3 deletions py/visdom/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def get_messages(self):
to_send = []
while len(self.messages) > 0:
message = self.messages.pop()
if type(message) is dict:
if isinstance(message, dict):
# Not all messages are being formatted the same way (JSON)
# TODO investigate
message = json.dumps(message)
Expand Down Expand Up @@ -656,7 +656,7 @@ def get_messages(self):
to_send = []
while len(self.messages) > 0:
message = self.messages.pop()
if type(message) is dict:
if isinstance(message, dict):
# Not all messages are being formatted the same way (JSON)
# TODO investigate
message = json.dumps(message)
Expand Down Expand Up @@ -769,7 +769,7 @@ def window(args):

def broadcast(self, msg, eid):
for s in self.subs:
if type(self.subs[s].eid) is list:
if isinstance(self.subs[s].eid, dict):
if eid in self.subs[s].eid:
self.subs[s].write_message(msg)
else:
Expand Down