Eric Snow <ericsnowcurren...@gmail.com> added the comment:

FWIW, if folks *are* checking for tuple (and I'd love to know why) then I'd 
recommend that they not. :)  A more Pythonic (and arguably generally better) 
approach would be to stick tightly to what data you need and take advantage of 
duck-typing.  When possible, try attribute access first if you expect that 
(e.g. namedtuple or struct seq).  Otherwise try use unpacking.

For example:

```
try:
    x, y = ret.x, ret.y
except AttributeError:
    pass
else:
    ...
```

```
try:
   x, y, _ = ret
except TypeError:
   pass
except ValueError:
   pass
else:
   ...
```

Either way is easier to follow than code that relies on type (and length) 
checking.  They also have the advantage of allowing arbitrary types that fit 
(duck-typing).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35914>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to