Skip to content

fix: allow num_labels property to return None when id2label is unset - #47069

Merged
zucchini-nlp merged 5 commits into
huggingface:mainfrom
SebTardif:fix/num-labels-optional-type
Jul 16, 2026
Merged

fix: allow num_labels property to return None when id2label is unset#47069
zucchini-nlp merged 5 commits into
huggingface:mainfrom
SebTardif:fix/num-labels-optional-type

Conversation

@SebTardif

@SebTardif SebTardif commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

CI

Summary

PretrainedConfig.num_labels was annotated as -> int but returned None when id2label is not set.

Change

Use int | None and document the optional return value.

Testing

Type annotation aligns with runtime behavior; no logic change.

The property was annotated as returning int but returned None when
id2label is missing, which contradicts the type and can break type
checkers and careful callers.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>

@zucchini-nlp zucchini-nlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense

@zucchini-nlp

Copy link
Copy Markdown
Member

Hopefully fixed now on main

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — automatic approval blocked

This PR was not automatically approved for CI because the security gate failed.

Possible reasons:

  • The PR touches 50 or more files — only PRs with fewer than 50 changed files are automatically approved
  • A changed file is outside the allowed directories (src/, tests/, docs/, utils/), has a disallowed extension (only .py, .txt, .md permitted outside tests/ and docs/), or is not .md/.yml inside docs/
  • A new high-severity security issue was detected in the changed Python files (Bandit check)

See the workflow run for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.

@zucchini-nlp
zucchini-nlp enabled auto-merge July 16, 2026 13:01
@zucchini-nlp
zucchini-nlp added this pull request to the merge queue Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 29153675305:2
Result: success | Jobs: 15 | Tests: 170,747 | Failures: 0 | Duration: 5h 1m

@HuggingFaceDocBuilderDev

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.

Merged via the queue into huggingface:main with commit d9f38e8 Jul 16, 2026
105 of 106 checks passed
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
…uggingface#47069)

The property was annotated as returning int but returned None when
id2label is missing, which contradicts the type and can break type
checkers and careful callers.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Co-authored-by: Raushan Turganbay <raushan@huggingface.co>
Sainava pushed a commit to Sainava/Sai-transformers that referenced this pull request Aug 3, 2026
…uggingface#47069)

The property was annotated as returning int but returned None when
id2label is missing, which contradicts the type and can break type
checkers and careful callers.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Co-authored-by: Raushan Turganbay <raushan@huggingface.co>
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.

3 participants