Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Simplify get_legend_handler method #6639
Conversation
mdboom
added the
needs_review
label
Jun 24, 2016
|
It is not clear for me why there was no check for unhashble legend_handler_keys = list(six.iterkeys(legend_handler_map))
if orig_handle in legend_handler_keys:Should I add such check or close pull request? |
tacaswell
added needs_revision and removed needs_review
labels
Jun 27, 2016
|
It is side-stepping having to do a check by using a simpler data structure. The I would revert the first set of changes, add a comment as to why it is that way, and leave the second half. Adding a test to the test suite that exercises the pathological input would be good too. |
tacaswell
added this to the
2.1 (next point release)
milestone
Jun 27, 2016
|
Yes, I understand this, but here we have a linear search in a dictionary by creating temporary list of dictionary keys and this list lives only withing the function. def get_legend_handler(legend_handler_map, orig_handle):
try:
hash(orig_handle)
except TypeError:
return None
... |
tacaswell
commented on an outdated diff
Jun 29, 2016
| @@ -565,19 +565,23 @@ def get_legend_handler(legend_handler_map, orig_handle): | ||
| method-resolution-order. If no matching key is found, it | ||
| returns None. | ||
| """ | ||
| - legend_handler_keys = list(six.iterkeys(legend_handler_map)) | ||
| - if orig_handle in legend_handler_keys: | ||
| - handler = legend_handler_map[orig_handle] | ||
| - else: | ||
| + try: | ||
| + hash(orig_handle) | ||
| + except TypeError: |
tacaswell
Owner
|
tacaswell
commented on an outdated diff
Jul 3, 2016
| @@ -565,19 +565,23 @@ def get_legend_handler(legend_handler_map, orig_handle): | ||
| method-resolution-order. If no matching key is found, it | ||
| returns None. | ||
| """ | ||
| - legend_handler_keys = list(six.iterkeys(legend_handler_map)) | ||
| - if orig_handle in legend_handler_keys: | ||
| - handler = legend_handler_map[orig_handle] | ||
| + try: | ||
| + hash(orig_handle) |
tacaswell
Owner
|
|
I have updated PR as per your suggestion and squashed multiple commits |
Kojoley commentedJun 24, 2016
I have simplified the
get_legend_handlermethod. There is no need to create list from keys oflegend_handler_mapand no need in two dictionary lookups (if key in dict: return dict[key]).Loop can be optimized even more, but will result in a code bloat, which does not worth of saving few cpu cycles.