Page MenuHomePhabricator

Make Claim.target_equals take precision into account
Open, Needs TriagePublic


The fact that Claim.target_equals() does WbTime comparison based only on year is counter-intuitive to me.

I would suggest making this take precision target.precision into account and demanding that target.precision < pywikibot.WbTime.PRECISION['year'] but would like to check what the original choice for comparing on year was.

Alternatively (or additionally) having a built in comparison where both target and value are WbTime would be useful. The method I use myself compares year, month, day etc. based on the relevant precision (so that 2010-01-01 and 2010-00-00 are equal but only if precision is year on both).

Event Timeline

Lokal_Profil raised the priority of this task from to Needs Triage.
Lokal_Profil updated the task description. (Show Details)
Lokal_Profil subscribed.

Alternatively I've misunderstood the purpose of Claim.target_equals()and the question it answers is instead "is the provided value within the precision of the target".

In which case if we should do something like:

if target.precision >= pywikibot.WbTime.PRECISION['year']:
    precision = int(1000000000) / pow(10, target.precision)
    return abs( - int(value)) <= precision
    return == int(value))

target_equals is mostly a utility method to assist -onlyif and -onlyifnot command line options for T69568.

Supporting year only was "minimum viable product", and was discussed in patchset 11&12 of .