Don't check `iterable()` before `len()`. #7767

Open
wants to merge 1 commit into
from

Projects

None yet

4 participants

@anntzer
Contributor
anntzer commented Jan 8, 2017

... because the former does not imply the latter anyways, e.g.
generators are iterables but unsized.

Now plot(zip([1, 2], [3, 4])) (py3) raises RuntimeError: matplotlib does not support generators (from cbook.safe_first_element) which is
probably the intended exception, rather than TypeError: object of type 'zip' has no len(). Perhaps this exception should be changed to a
TypeError, by the way...

@anntzer anntzer Don't check `iterable()` before `len()`.
... because the former does not imply the latter anyways, e.g.
generators are iterables but unsized.

Now `plot(zip([1, 2], [3, 4]))` (py3) raises `RuntimeError: matplotlib
does not support generators` (from `cbook.safe_first_element`) which is
probably the intended exception, rather than `TypeError: object of type
'zip' has no len()`.  Perhaps this exception should be changed to a
`TypeError`, by the way...
aeb1898
@codecov-io

Current coverage is 62.11% (diff: 100%)

Merging #7767 into master will decrease coverage by <.01%

@@             master      #7767   diff @@
==========================================
  Files           174        174          
  Lines         56028      56011    -17   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          34805      34793    -12   
+ Misses        21223      21218     -5   
  Partials          0          0          

Powered by Codecov. Last update eba130f...aeb1898

self.stale = True
def _get_loc(self):
return self._loc_real
_loc = property(_get_loc, _set_loc)
- def _findoffset_best(self, width, height, xdescent, ydescent, renderer):
@phobson
phobson Jan 9, 2017 Member

are these changes related to the title of the PR?

@anntzer
anntzer Jan 10, 2017 Contributor

The idea was to fix the line a bit below (if iterable(self._loc) and len(self._loc) == 2) but as you can see the new logic is just to see whether _loc is a 0-9 location and otherwise unpack it, so it seemed reasonable to squash the if ... elif ... else into a single function rather than keeping them artificially separated.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment