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 str subclass validation for enums #1273

Merged
merged 9 commits into from May 21, 2024
Merged

Fix str subclass validation for enums #1273

merged 9 commits into from May 21, 2024

Conversation

sydney-runkle
Copy link
Member

@sydney-runkle sydney-runkle commented Apr 18, 2024

Fix pydantic/pydantic#9265
Fix pydantic/pydantic#9375

This is kind of gross, but preserves behavior from 2.6 that I think is valid.

@sydney-runkle sydney-runkle changed the title Various enum fixes for upcoming patch Fix str subclass validation for enums Apr 18, 2024
Copy link

codspeed-hq bot commented Apr 18, 2024

CodSpeed Performance Report

Merging #1273 will not alter performance

Comparing enum_fixes (cad59ca) with main (b777774)

Summary

✅ 155 untouched benchmarks

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Do we have the same problem for int subclasses? (I think bools cannot be subclassed.)

I wonder if there's a more general structural issue here (like e.g. maybe lookup.validate should take a strict argument)?

tests/validators/test_enums.py Outdated Show resolved Hide resolved
sydney-runkle and others added 2 commits April 18, 2024 10:49
@sydney-runkle
Copy link
Member Author

Alright, so we want to move forward with this by modifying how we validate enums (moving away from the literal validation logic). Definitely something we still want to fix, but going to wait on 2.7.2 for this one 👍

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise I don't love it, but I prefer it to copy & pasting lots of literal logic.

src/validators/enum_.rs Outdated Show resolved Hide resolved
src/validators/enum_.rs Outdated Show resolved Hide resolved
src/validators/enum_.rs Outdated Show resolved Hide resolved
src/validators/enum_.rs Outdated Show resolved Hide resolved
src/validators/enum_.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@sydney-runkle sydney-runkle merged commit 727deee into main May 21, 2024
28 checks passed
@sydney-runkle sydney-runkle deleted the enum_fixes branch May 21, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants