Skip to content

gh-139122: Restore generic attribute initialization of C UUIDs - #160203

Open
1st1 wants to merge 1 commit into
python:mainfrom
1st1:writeable_int
Open

1st1 wants to merge 1 commit into
python:mainfrom
1st1:writeable_int

Conversation

@1st1

@1st1 1st1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Pydantic constructs UUIDs by calling the type's tp_new and setting int and is_safe through PyObject_GenericSetAttr. The C UUID implementation made these descriptors read-only, so that construction path fails after #139123.

Add setters for both descriptors, restoring construction through object.__setattr__ and PyObject_GenericSetAttr. Ordinary assignment still raises TypeError, matching the Python UUID implementation. The integer setter validates the value and converts it into a temporary 16-byte, big-endian buffer before updating the UUID, so failed conversions leave the object unchanged. Successful replacement invalidates the cached hash.

Tests cover construction without __init__, subclasses, 128-bit boundary values, integer subclasses, hash invalidation, and rejected assignments preserving the original value and hash.

Validation: the full test_uuid suite passed (165 tests, 22 skipped), including -R 3:3 reference leak checks. A direct PyObject_GenericSetAttr smoke test reproduced Pydantic's construction sequence successfully. Ruff and git diff --check passed.

Refs #139122.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 22, 2026
@1st1
1st1 requested a review from picnixz October 22, 2026 05:23
@picnixz

picnixz commented Oct 22, 2026

Copy link
Copy Markdown
Member

Ok that's weird: I deleted the file from your branch (and it shows as deleted) but GH is still showing it here. I will wait a bit (or maybe you should force push again). Sorry for the mess though (otherwise LGTM!)

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

Labels

awaiting merge skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants