Adam Johnson
Read post

Python: fix TypeError: NotImplemented should not be used in a boolean context

Python 3.14 turns a long-standing DeprecationWarning into a hard TypeError: using NotImplemented in a boolean context is now illegal. This commonly surfaces in hand-written __ne__() methods that call self.__eq__() and negate the result with 'not', or in the filter(None.__ne__, values) idiom for removing None from lists. The root cause is that NotImplemented is a truthy singleton meant to signal 'try something else' to Python's comparison machinery, not to be evaluated as a bool. The fix for __ne__ is simply to delete it — Python 3+ already provides a correct default. The fix for the filter idiom is a list comprehension using 'is not None', which is also ~15x faster.

    #python
Jul 28•4m read time•From adamj.eu
Post cover image
Table of contents
The fixAnother caseFin
137 Impressions
Adam Johnson's image
Adam Johnson

AdamJ's platform covers topics related to software development, technology trends, and coding tutor...

54 Followers

•

444 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard