Skip to content

Add py.typed#37022

Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom
cyyever:pytyped
Apr 2, 2025
Merged

Add py.typed#37022
Rocketknight1 merged 1 commit intohuggingface:mainfrom
cyyever:pytyped

Conversation

@cyyever
Copy link
Copy Markdown
Contributor

@cyyever cyyever commented Mar 27, 2025

py.typed is a marker file to support typing. See pep 561. It's used to indicate that transformer has typing support in the source code and tools such as mypy and pylint can take advantage of that. Therefore, we don't need an additional pyi file for typing.

@github-actions
Copy link
Copy Markdown
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@github-actions github-actions bot marked this pull request as draft March 27, 2025 00:17
@cyyever cyyever marked this pull request as ready for review March 27, 2025 00:17
Copy link
Copy Markdown
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Hey could you give us a bit more info about what this entails to?

@cyyever
Copy link
Copy Markdown
Contributor Author

cyyever commented Mar 27, 2025

Added

@Rocketknight1
Copy link
Copy Markdown
Member

I'm not sure about this - I think a lot of our library isn't actually fully typed, and type hints are "nice to have" rather than mandatory. Will adding a py.typed create lots of errors whenever our types are missing or inaccurate?

@cyyever
Copy link
Copy Markdown
Contributor Author

cyyever commented Mar 27, 2025

@Rocketknight1 No Python project has perfect typing in practice.Errors are generated when the user enables type inference. Without py.typed in this case, errors are triggered for each transformer symbol, and now we can at least provide correct types some symbols and leave Any for other symbols.
Pytorch and NumPy all use py.typed, however, their typing is clearly not 100% correct.

@Rocketknight1
Copy link
Copy Markdown
Member

Seems okay to me in that case, but I'll defer to core maintainers since it affects the entire project, cc @ArthurZucker @Cyrilvallez @LysandreJik

Copy link
Copy Markdown
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Thanks for the details, LGTM. At some point we did have a file like that.

@cyyever cyyever force-pushed the pytyped branch 3 times, most recently from 8db7e42 to 9d5dec9 Compare March 31, 2025 14:51
@Rocketknight1 Rocketknight1 merged commit 7613cf1 into huggingface:main Apr 2, 2025
18 checks passed
@Rocketknight1
Copy link
Copy Markdown
Member

Merging lots of your PRs now the CI is green, thanks again @cyyever!

@cyyever cyyever deleted the pytyped branch April 2, 2025 13:39
zucchini-nlp pushed a commit to BakerBunker/transformers that referenced this pull request Apr 2, 2025
duanjunwen pushed a commit to duanjunwen/transformers that referenced this pull request Apr 3, 2025
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
soghomon-b pushed a commit to soghomon-b/transformers that referenced this pull request Aug 24, 2025
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