[tor-dev] Relay Dashboard Code Review

meejah meejah at meejah.ca
Wed Aug 5 17:56:09 UTC 2015


Damian Johnson <atagar at torproject.org> writes:

> Very minor thing, but little odd using dict() that way.

Personally, I don't find it that odd ;) and prefer it since braces can
define sets or dicts in Python, and using dict(...) makes it a little
more explicit.

BTW, your counter-example is a syntax error; you need to quote the keys,
which is another reason I prefer the kwarg-style dict definition...

> Generally it's good idea to both only catch the exception types you need, and
> include the exception in the message so there's some hint for
> troubleshooting.

Yes, you should really never have a bare "except:" to avoid catching
things like MemoryError or KeyboardInterrupt yourself.

>   def get_websockets(ws_type = None):
>     websocket = WEBSOCKETS.get(ws_type, [])
>     return websocket if websocket else None

How about just:

    def get_websockets(ws_type=None):
        return WEBSOCKETS.get(ws_type, None)

-- 
meejah


More information about the tor-dev mailing list