Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

fix case of checking truthiness of NotImplemented#1298

Merged
sydney-runkle merged 1 commit into
mainfrom
dh/negative-comparison
May 22, 2024
Merged

fix case of checking truthiness of NotImplemented#1298
sydney-runkle merged 1 commit into
mainfrom
dh/negative-comparison

Conversation

@davidhewitt

Copy link
Copy Markdown
Collaborator

Change Summary

At the moment when checking for non-negative integers, we can get false-postives from types that aren't integer.

e.g. the original logic was equivalent to

>>> bool("__all__".__lt__(0))
<stdin>:1: DeprecationWarning: NotImplemented should not be used in a boolean context
True

... because comparisons between strings and integers are not implemented, and the dunder method does not raise type errors on NotImplemented.

Related issue number

Fixes pydantic/pydantic#9328

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@sydney-runkle sydney-runkle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sydney-runkle sydney-runkle enabled auto-merge (squash) May 22, 2024 13:35
@codspeed-hq

codspeed-hq Bot commented May 22, 2024

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #1298 will not alter performance

Comparing dh/negative-comparison (293f4c3) with main (2415f42)

Summary

✅ 155 untouched benchmarks

@sydney-runkle sydney-runkle merged commit 88a8a30 into main May 22, 2024
@sydney-runkle sydney-runkle deleted the dh/negative-comparison branch May 22, 2024 13:40
@MatthieuSarter

Copy link
Copy Markdown

Thanks for the fix 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude with __all__ fails on Sequence fields

3 participants