python-chess v0.5.0
New in this release:
-
PGN parsing is now more robust:
read_game()
ignores invalid tokens.
Still exceptions are going to be thrown on illegal or ambiguous moves, but
this behaviour can be changed by passing anerror_handler
argument.>>> # Raises ValueError: >>> game = chess.pgn.read_game(file_with_illegal_moves) >>> # Silently ignores errors and continues parsing: >>> game = chess.pgn.read_game(file_with_illegal_moves, None) >>> # Logs the error, continues parsing: >>> game = chess.pgn.read_game(file_with_illegal_moves, logger.exception)
If there are too many closing brackets this is now ignored.
Castling moves like 0-0 (with zeros) are now accepted in PGNs.
TheBitboard.parse_san()
method remains strict as always, though.Previously the parser was strictly following the PGN spefification in that
empty lines terminate a game. So a game like[Event "?"] { Starting comment block } 1. e4 e5 2. Nf3 Nf6 *
would have ended directly after the starting comment. To avoid this, the
parser will now look ahead until it finds at least one move or a termination
marker like*
,1-0
,1/2-1/2
or0-1
. -
Introduce a new function
scan_headers()
to quickly scan a PGN file for
headers without having to parse the full games. -
Minor testcoverage improvements.