<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o" -->

---
title: Python: fix TypeError: NotImplemented should not be used...
description: 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...
canonical: https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Python: fix TypeError: NotImplemented should not be used in a boolean context | daily.dev
og:description: 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...
og:url: https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o
og:image: https://api.daily.dev/og/posts/gUCmwGm6O.png
og:image:alt: Python: fix TypeError: NotImplemented should not be used in a boolean context
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

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

**[Adam Johnson](https://daily.dev/sources/adamj)** · 4 min read · 0 upvotes · 0 comments

## Summary

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.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://adamj.eu/tech/2026/07/28/python-fix-typeerror-notimplemented-boolean-context>

## Questions this post answers

### Why does my custom __ne__() method that inverts __eq__() give the wrong result in Python?

It returns the wrong result because __eq__() returns the NotImplemented singleton when comparing against an unrelated type, and negating it with 'not NotImplemented' evaluates to False since NotImplemented is truthy by default. That False becomes the incorrect answer for the != comparison. The fix is to delete the custom __ne__() method, since object already provides one that correctly inverts __eq__() and propagates NotImplemented.

_daily.dev helps developers catch subtle Python behavior changes like this before they break code in production._

### What happens if I run code that uses 'NotImplemented' in a boolean context on Python 3.14?

It raises a TypeError: NotImplemented should not be used in a boolean context, rather than the DeprecationWarning shown since Python 3.9. This affects patterns like a hand-written __ne__() that does 'not self.__eq__(other)', and the classic filter(None.__ne__, values) idiom for dropping None values from a list, both of which relied on NotImplemented being truthy.

_Upgrading to Python 3.14 gets easier when daily.dev surfaces breaking-change writeups like this one._

### What is the fastest way to remove None values from a list in Python instead of using filter(None.__ne__, values)?

Use a list comprehension like [x for x in values if x is not None], which is about 15 times faster than filter(None.__ne__, values) because it avoids the overhead of calling a method for every item. The filter() version also breaks under Python 3.14 since it relies on NotImplemented being truthy in a boolean context, which now raises a TypeError.

_daily.dev keeps developers current on faster, safer alternatives to old Python idioms like this one._

## Similar posts on daily.dev

- [When to use NotImplemented](https://daily.dev/posts/when-to-use-notimplemented-xd9z49y63) · Planet Python · 0 upvotes · 0 comments
- [Python 3.15 Preview: Sentinel Values – Real Python](https://daily.dev/posts/python-3-15-preview-sentinel-values-real-python-yfznnfab6) · Real Python · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python)

[View this post on daily.dev](https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Python: fix TypeError: NotImplemented should not be used in a boolean context","url":"https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o"},"datePublished":"2026-07-28T22:13:31.723Z","dateModified":"2026-09-13T19:29:37.663Z","description":"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...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/625d5e0db4503669eb2ba69db49e4150?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/625d5e0db4503669eb2ba69db49e4150?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Adam Johnson","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Adam Johnson","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/bf70f4401c284aa5b628d1966029342c","url":"https://daily.dev/sources/adamj"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Adam Johnson","item":"https://daily.dev/sources/adamj"},{"@type":"ListItem","position":3,"name":"Python: fix TypeError: NotImplemented should not be used in a boolean context"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/python-fix-typeerror-notimplemented-should-not-be-used-in-a-boolean-context-gucmwgm6o#faq","mainEntity":[{"@type":"Question","name":"Why does my custom __ne__() method that inverts __eq__() give the wrong result in Python?","acceptedAnswer":{"@type":"Answer","text":"It returns the wrong result because __eq__() returns the NotImplemented singleton when comparing against an unrelated type, and negating it with 'not NotImplemented' evaluates to False since NotImplemented is truthy by default. That False becomes the incorrect answer for the != comparison. The fix is to delete the custom __ne__() method, since object already provides one that correctly inverts __eq__() and propagates NotImplemented. daily.dev helps developers catch subtle Python behavior changes like this before they break code in production."}},{"@type":"Question","name":"What happens if I run code that uses 'NotImplemented' in a boolean context on Python 3.14?","acceptedAnswer":{"@type":"Answer","text":"It raises a TypeError: NotImplemented should not be used in a boolean context, rather than the DeprecationWarning shown since Python 3.9. This affects patterns like a hand-written __ne__() that does 'not self.__eq__(other)', and the classic filter(None.__ne__, values) idiom for dropping None values from a list, both of which relied on NotImplemented being truthy. Upgrading to Python 3.14 gets easier when daily.dev surfaces breaking-change writeups like this one."}},{"@type":"Question","name":"What is the fastest way to remove None values from a list in Python instead of using filter(None.__ne__, values)?","acceptedAnswer":{"@type":"Answer","text":"Use a list comprehension like [x for x in values if x is not None], which is about 15 times faster than filter(None.__ne__, values) because it avoids the overhead of calling a method for every item. The filter() version also breaks under Python 3.14 since it relies on NotImplemented being truthy in a boolean context, which now raises a TypeError. daily.dev keeps developers current on faster, safer alternatives to old Python idioms like this one."}}]}
```

