rpdelaney-archive / python-chess-annotator

Reads chess games in PGN format and adds annotations using an engine
GNU General Public License v3.0
62 stars 29 forks source link

Use reversed() instead of this weird inverted manual for loop stuff #22

Open rpdelaney opened 5 years ago

rpdelaney commented 5 years ago

This is one of those "what was I thinking?" moments now that I've had some time to level up my python since I wrote this.

rpdelaney commented 5 years ago

Might require changes to python-chess.

https:/docs.python.org/3/library/functions.html#reversed

reversed(seq)

    Return a reverse iterator. seq must be an object which has 
a __reversed__() method or supports the sequence protocol 
(the __len__() method and the __getitem__() method with integer 
arguments starting at 0).
rpdelaney commented 5 years ago

Consider extending with a superclass also, in the event that python-chess can't be changed.

rpdelaney commented 5 years ago

niklasf/python-chess/issues/319 enabled use of reversed(node.mainline()): node.mainline() now returns an iterator of GameNodes, not Moves, and .mainline() supports the sequence protocol.