Fixing “None” Not Callable Error in Mypy

Photo by David Travis on Unsplash

The mypy static type checker always complain about using a dictionary to call functions. Especially this code segment from my chess program that I’m writing in Python as a learning exercise.

status = {Bishop: self.validate_move_bishop,
King: self.validate_move_king,
Knight: self.validate_move_knight,
Pawn: self.validate_move_pawn,
Queen: self.validate_move_queen,
Rook: self.validate_move_rook,
}.get(type(self._board[start]))(start, end)

This message, error: “None” not callable, always leave me cross-eyed at times. I came up with a solution for that problem.

Read my essay and follow me on Medium. Your support is greatly appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.