Skip to content

Conversation

@qstokkink
Copy link
Contributor

@qstokkink qstokkink commented Aug 6, 2025

Fixes #7996

This PR cherry-picks the Python typing commits from master and fixes them up. There intent here is to NOT make any API changes, only to introduce typing. The first four commits are cherry-picked and only the second one (
965d9f2) is rewritten.

  • One GitHub Actions job is added: check_wheel_type_exposure enforces both exposed type presence and type consistency.
  • One entry is added to .pre-commit-config.yaml: flake8-pyi-run enforces modern Python syntax in the stubs.
  • I updated some Python files in bindings/python/ to verify the typing (it is impossible to properly test types using a file that does not use types itself).
  • One Python TestCase is added to somewhat match function stub signatures to their actual bindings.

@qstokkink qstokkink changed the title Add RC_2_0 Python bindings Add RC_2_0 Python bindings stubs Aug 11, 2025
@qstokkink qstokkink changed the title Add RC_2_0 Python bindings stubs Add RC_2_0 Python type stubs Aug 11, 2025
@qstokkink qstokkink force-pushed the merge_master_typestubs branch 2 times, most recently from 316466c to 9bb82cd Compare August 11, 2025 08:38
@xavier2k6
Copy link
Contributor

@qstokkink Why not use https://github.com/PyCQA/flake8-pyi (25.5.0) in pre-commit?

@qstokkink qstokkink force-pushed the merge_master_typestubs branch from 9bb82cd to 15d6b0a Compare August 11, 2025 13:52
@qstokkink
Copy link
Contributor Author

@xavier2k6 Because I presumed that only works if the repo has a .pre-commit-hooks.yaml file. I'm not a pre-commit poweruser by any means, though.

Can you share a .pre-commit-config.yaml excerpt/configuration (that works)?

@qstokkink qstokkink force-pushed the merge_master_typestubs branch 6 times, most recently from 7a26b58 to 4f64a61 Compare August 11, 2025 20:35
@qstokkink qstokkink marked this pull request as ready for review August 12, 2025 08:11
@qstokkink
Copy link
Contributor Author

I marked this as "ready". Not because there is nothing left to change, but more because I'm already roughly 5k lines above what I think the maximum PR size should be (though most of this is in the 5,252 lines of the Python type stubs).

@arvidn
Copy link
Owner

arvidn commented Aug 16, 2025

you're making a lot of changes to the actual bindings themselves. I don't think that's reasonable, it really risks breaking compatibility. Is there a good reason to not just add type stubs for the existing bindings?

Previously, only the first version of a PR had its wheels cached and used until the cache timed out. Even if there were changes to the files that should be in the wheels.
@qstokkink qstokkink force-pushed the merge_master_typestubs branch from f6d11d6 to b3172df Compare August 17, 2025 11:33
@qstokkink
Copy link
Contributor Author

qstokkink commented Aug 17, 2025

@arvidn Changed. I ripped all of the non-essential stuff out now.

[EDIT] If you care about the reason: I figured that pulling in as much of the non-impactful changes as possible would make it easier to merge back from RC_2_0 to master. That would make the typing-related things my problem in this PR, instead of the problem of whoever does that backmerge.
[EDIT 2] I can do that backmerge into master, if you want me to.

@stabldev
Copy link

stabldev commented Nov 8, 2025

hi, any update on this?
i'd like to see libtorrent with stubs :D

@qstokkink
Copy link
Contributor Author

@stabldev You can download and play with the wheels of this PR (here: https://github.com/arvidn/libtorrent/actions/runs/17020524696?pr=8007). Feedback is welcome. It would be nice to have some "testimonials" that the typing is correct and useful.

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.

Pypi builds are missing type stubs

5 participants