Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix case of checking truthiness of NotImplemented #1298

Merged
merged 1 commit into from
May 22, 2024

Conversation

davidhewitt
Copy link
Contributor

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

Copy link
Member

@sydney-runkle sydney-runkle left a comment

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
Copy link

codspeed-hq bot commented May 22, 2024

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
27 checks passed
@sydney-runkle sydney-runkle deleted the dh/negative-comparison branch May 22, 2024 13:40
@MatthieuSarter
Copy link

Thanks for the fix 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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