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.

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.