Fixing A String Issue with Enum.name in MyPy

Photo by Mel Poole on Unsplash

While cleaning up code in my chess program that I’m writing in Python as a learning exercise, I came across yet another problem with the mypy static type checker. This time with the Enum.name attribute.

color = Color(self._color).name.capitalize()

The statement worked but mypy reported an error message.

error: Item “None” of “Optional[str]” has no attribute “capitalize”

I came up with a solution for that problem.

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

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.

Fixing The Incompatible Dunder Method Error in Mypy

Photo by Stephanie Mulrooney on Unsplash

While cleaning up my code in a chess program that I’m writing in Python as a learning exercise, I created an Enum class to represent the starting ranks for certain pieces on the board. Since I wanted the Enum to also behave like a list, I added that to the class definition. The mypy static type checker reported an incompatible __hash__ dunder method error between list and Enum. I came up with a solution for that problem.

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