Skip to content

[Fix] Remove private _MISSING_TYPE import from dataclasses module#4322

Merged
Wauplin merged 1 commit into
huggingface:mainfrom
xsuchy:missing-type
Jun 8, 2026
Merged

[Fix] Remove private _MISSING_TYPE import from dataclasses module#4322
Wauplin merged 1 commit into
huggingface:mainfrom
xsuchy:missing-type

Conversation

@xsuchy

@xsuchy xsuchy commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

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


Note

Low Risk
Annotation-only change in two helpers; no logic paths altered and MISSING handling is unchanged.

Overview
Fixes ImportError on Python 3.15 by dropping the private dataclasses._MISSING_TYPE import that was removed upstream.

In validated_field and as_validated_field, parameter annotations for default and default_factory are simplified from Any | _MISSING_TYPE (and Callable[[], Any] | _MISSING_TYPE for the factory) to Any, which already covers the MISSING sentinel. 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.

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>
@bot-ci-comment

bot-ci-comment Bot commented Jun 8, 2026

Copy link
Copy Markdown

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.

@Wauplin Wauplin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for reporting 👍

@Wauplin Wauplin merged commit 4d2d5f3 into huggingface:main Jun 8, 2026
21 of 22 checks passed
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.30%. Comparing base (1daa48b) to head (c6f8ed1).
⚠️ Report is 406 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xsuchy xsuchy deleted the missing-type branch June 8, 2026 10:44
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.19.0 release.

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.

2 participants