[request] findAll() should force getLastMatches() to return None if nothing was found

Bug #779099 reported by RaiMan
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SikuliX
Fix Released
Wishlist
Unassigned

Bug Description

This would help to write lean code.

Currently getLastMatches() returns a Finder object in all cases. If nothing was found, the first entry (hasNext() returns True) is set to None.

So if you handle the FindFailed exception or ignore it, you at least have to pop one entry to check it for None. If it is not None and you want to loop through all entries, you cannot push the first entry back - this has to be handled as a special case in the while/for loop. Or you have to set up additional switches to catch None in the first entry.

a compact workaround currently with the cost of an additional search when successful:
matches = findAll(img) if exists(img, 0) else ()
for x in matches:
   pass # will not execute if nothing found

This is possible, but I guess the average Sikuli user might not find this solution.

RaiMan (raimund-hocke)
Changed in sikuli:
importance: Undecided → Wishlist
Changed in sikuli:
status: New → Fix Committed
milestone: none → x1.0-rc3
summary: - [request] findAll() should force getLastMatch() to return None if
+ [request] findAll() should force getLastMatches() to return None if
nothing was found
RaiMan (raimund-hocke)
Changed in sikuli:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.