fix: fully register dynamic file types for enum lookup and serialization
Summary
create_file_type() updates only the enum's name mapping. Its returned type can be found by MIME type or extension, but is absent from enum iteration and cannot be reconstructed with FileType(value). Unpickling a registered type also raises ValueError, including when a process worker has registered that same type before receiving the task. On Python 3.12, attribute access such as FileType.CUSTOM is missing as well.
Complete registration in the name attribute, ordered member list, and value mapping. Re-registering a custom name retains the existing replacement behavior without duplicating iteration entries. Reject names that would replace a built-in member, collide with another member's value, or overwrite an existing class attribute, before changing any registry state.
Each process still needs to register a custom type before unpickling it; this change does not install a registration in another process automatically.
Validation
- 12 regression/control cases cover name/value/attribute lookup, ordered and reversed enum iteration, pickle protocols 0 and 5, a real spawned
ProcessPoolExecutorworker with an initializer, custom re-registration, built-in member preservation, collision rejection without partial changes, MIME aliases, public file detection, and partitioner registration. - Base revision: 10 failed, 2 passed. After the fix, the new cases and existing file-type model suite report 116 passed, using normal package imports on Python 3.12.14.
- Ruff 0.17.5
check,format --check, andgit diff --checkpass. The full repository suite was not run.
Checklist
- The PR title is a user-facing release-note entry with a conventional commit prefix.
- Apply a category label (
enhancement,bug, or an appropriate existing label), or ask a maintainer to apply it. Please applybug. - For breaking changes, use
!in the title and explain impact and migration above. Existing valid custom registrations retain their signatures; conflicting registrations now raise instead of leaving inconsistent enum state.