[Fix] Remove private _MISSING_TYPE import from dataclasses module#4322
Merged
Conversation
Python 3.15 removed the private `_MISSING_TYPE` from the `dataclasses`
module, causing an ImportError on startup:
Traceback (most recent call last):
File "/usr/lib/python3.15/site-packages/huggingface_hub/__init__.py"
from .dataclasses import strict, validate_typed_dict, validated_field
File "/usr/lib/python3.15/site-packages/huggingface_hub/dataclasses.py", line 5
from dataclasses import _MISSING_TYPE, MISSING, Field, field, fields, make_dataclass
ImportError: cannot import name '_MISSING_TYPE' from 'dataclasses'
(/usr/lib64/python3.15/dataclasses.py)
`_MISSING_TYPE` was only used in type annotations for `validated_field`
and `as_validated_field`, always unioned with `Any`. Since `Any` already
encompasses all types including the `MISSING` sentinel, the
`_MISSING_TYPE` half of the union was redundant — removing it changes
no runtime or type-checking behavior.
Key decision: use `Any` directly instead of deriving the type with
`type(MISSING)` or creating a compatibility shim, since `Any` was
already present in every union where `_MISSING_TYPE` appeared.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2481411
Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4322 +/- ##
==========================================
+ Coverage 75.00% 76.30% +1.30%
==========================================
Files 145 173 +28
Lines 13978 20312 +6334
==========================================
+ Hits 10484 15500 +5016
- Misses 3494 4812 +1318 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
This PR has been shipped as part of the v1.19.0 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python 3.15 removed the private
_MISSING_TYPEfrom thedataclassesmodule, causing an ImportError on startup:Traceback (most recent call last):
File "/usr/lib/python3.15/site-packages/huggingface_hub/init.py"
from .dataclasses import strict, validate_typed_dict, validated_field
File "/usr/lib/python3.15/site-packages/huggingface_hub/dataclasses.py", line 5
from dataclasses import _MISSING_TYPE, MISSING, Field, field, fields, make_dataclass
ImportError: cannot import name '_MISSING_TYPE' from 'dataclasses'
(/usr/lib64/python3.15/dataclasses.py)
_MISSING_TYPEwas only used in type annotations forvalidated_fieldandas_validated_field, always unioned withAny. SinceAnyalready encompasses all types including theMISSINGsentinel, the_MISSING_TYPEhalf of the union was redundant — removing it changes no runtime or type-checking behavior.Key decision: use
Anydirectly instead of deriving the type withtype(MISSING)or creating a compatibility shim, sinceAnywas already present in every union where_MISSING_TYPEappeared.Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2481411
Assisted-By: Claude Opus 4.6 noreply@anthropic.com
Note
Low Risk
Annotation-only change in two helpers; no logic paths altered and
MISSINGhandling is unchanged.Overview
Fixes ImportError on Python 3.15 by dropping the private
dataclasses._MISSING_TYPEimport that was removed upstream.In
validated_fieldandas_validated_field, parameter annotations fordefaultanddefault_factoryare simplified fromAny | _MISSING_TYPE(andCallable[[], Any] | _MISSING_TYPEfor the factory) toAny, which already covers theMISSINGsentinel. No runtime or validation behavior changes—only import compatibility.Reviewed by Cursor Bugbot for commit c6f8ed1. Bugbot is set up for automated code reviews on this repo. Configure here.