This is an archive of the discontinued Mercurial Phabricator instance.

py3: prevent comparison of integers with None
AbandonedPublic

Authored by pulkit on Jun 9 2018, 1:37 PM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

On py2, we can compare integer type with NoneType but on py3 we can't.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

pulkit created this revision.Jun 9 2018, 1:37 PM
yuja added a subscriber: yuja.Jun 9 2018, 10:18 PM
for e in log:
    if e.commitid:
  • mindate[e.commitid] = min(e.date, mindate.get(e.commitid))

+ if mindate.get(e.commitid) is None:
+ mindate[e.commitid] = None
+ else:
+ mindate[e.commitid] = min(e.date, mindate.get(e.commitid))

  1. Merge changesets log.sort(key=lambda x: (mindate.get(x.commitid), x.commitid, x.comment,

mindate is also used here as a comparison key. Filling it to None would
make things worse.

I think the original code, which just fills every mindate element with None,
was wrong. Instead, it should probably keep the minimum value only if exists,

if e.commitid in mindate:
    mindate[e.commitid] = min(e.date, mindate[e.commitid])
else:
    mindate[e.commitid] = e.date

and later falls back to the null value.

log.sort(key=lambda x: (mindate.get(x.commitid, (lowest_or_highest_value?, 0)
pulkit abandoned this revision.Jun 14 2018, 7:48 AM

Not required anymore.