Alternative Fix for Incompatible Dunder Method Error in Mypy

When a neat trick in Python becomes a side effect.

Photo by Phil Hearing on Unsplash
class Rank(list, Enum):
HIGH = [1, 8]
PAWN = [2, 7]
>>> enums.Rank.HIGH
<Rank.HIGH: (1, 8)>
>>> enums.Rank.HIGH. Value
(1, 8)
>>> 8 in enums.Rank.HIGH
True
>>> 7 in enums.Rank.HIGH
False
class Rank(list, Enum): # type: ignore
HIGH = [1, 8]
PAWN = [2, 7]
Missing Rank class in the static HTML page. Image by C.D. Reimer.
.. automodule:: enums
:members: Color, PieceType, Ranks
Rank class with missing source link in the static HTML page. Image by C.D. Reimer.
W8301: Use tuple instead of list for a non-mutated sequence (use-tuple-over-list)
class Rank(tuple, Enum):
HIGH = (1, 8)
PAWN = (2, 7)
Rank class updated to appear with source link in the static HTML page. Image by C.D. Reimer.

--

--

C.D. Reimer makes topical videos about comic cons, pop culture, Silicon Valley and technology on YouTube. https://www.youtube.com/cdreimer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
C.D. Reimer

C.D. Reimer makes topical videos about comic cons, pop culture, Silicon Valley and technology on YouTube. https://www.youtube.com/cdreimer