Message325543
@Serhiy I like the "convert to a tuple" idea before returning *better*, though I think I'd prefer to just check that it's tuple-like, something like:
if not all(hasattr(return_val, attr) for attr in ['__getitem__', '__len__']) or len(return_val) != 2:
warnings.warn("divmod must return a Sequence of length 2. " +
"This will be an exception in Python 3.9+",
Deprecationwarning)
Or some similar equivalent to `if not isinstance(return_val, collections.abc.Sequence) or len(return_val) != 2`.
That said, the PR seems to have already run into an issue, which is that `unittest.mock.MagicMock` returns a `unittest.mock.MagicMock` from `divmod`, which is not a 2-tuple. |
|
Date |
User |
Action |
Args |
2018-09-17 13:37:42 | p-ganssle | set | recipients:
+ p-ganssle, rhettinger, mark.dickinson, zach.ware, serhiy.storchaka, xtreak |
2018-09-17 13:37:42 | p-ganssle | set | messageid: <1537191462.35.0.956365154283.issue34676@psf.upfronthosting.co.za> |
2018-09-17 13:37:42 | p-ganssle | link | issue34676 messages |
2018-09-17 13:37:42 | p-ganssle | create | |
|