Skip to content

Add type hints for python bindings - #3146

Open
historicattle wants to merge 2 commits into
capstone-engine:nextfrom
historicattle:type
Open

historicattle wants to merge 2 commits into
capstone-engine:nextfrom
historicattle:type

Conversation

@historicattle

@historicattle historicattle commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description
Add type hints for python bindings
Correct the number of operands for AArch64 to be 16 so that its the same with
https://github.com/capstone-engine/capstone/blob/next/include/capstone/aarch64.h#L2869

Corrected the AArch64Op class by adding pred() and removing sysop()
Fixed some linter / formatting warnings

(the changes arent as big as the diff makes it seem)

Test plan
all tests pass, no new ones added

Closing issues
closes #2841

Correct the number of operands for AArch64 to be 16
@github-actions github-actions Bot added the Python Bindings label Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (next@8b95af3). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3146   +/-   ##
=======================================
  Coverage        ?   61.45%           
=======================================
  Files           ?      243           
  Lines           ?    56829           
  Branches        ?    10082           
=======================================
  Hits            ?    34925           
  Misses          ?    16708           
  Partials        ?     5196           

☔ 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.

@historicattle
historicattle marked this pull request as ready for review October 28, 2026 06:56

@Rot127 Rot127 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.

Looks good. But please add it to the Python linter job and add one for the typing if not too much trouble.

Comment thread bindings/python/capstone/m68k.py Resolved
@Rot127 Rot127 mentioned this pull request Nov 9, 2026
6 of 17 tasks
@Rot127

Rot127 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Ping :)
Would be nice to have it in the Beta release

@github-actions github-actions Bot added the Github-files Github related files label Nov 14, 2026
Use Sequence instead of tuples
Fix incorrect annotations
Add py.typed to tell mypy that type hints exist
Fix some linter warnings
@historicattle

Copy link
Copy Markdown
Contributor Author

there was no option where i could get mypy to find out which attributes were missing, so I added a small script that checks it. (also i wasnt sure if adding to an existing workflow was appropriate? so created a new one)

Also i added a py.typed file to tell the type checker that capstone has type hints. Otherwise they would ignore our type hints.

(sorry the changes took a bit long :( )

@Antelox

Antelox commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Hi @historicattle, thanks for the time spent working on this and to creating this PR. I would suggest to separate formatting from addition of type annotations since they are 2 unrelated changes.
A while back I was discussing with @Rot127 to introduce some linter job to check code formatting and type hints. For such thing I was suggesting to use tools from Astral: ruff and ty

if you agree I would like to have the formatting separate to not mess up with the actual changes and introduce there in the workflow the linter job. I can take care of this second part if fine for you. @Rot127 do you agree?

@historicattle

Copy link
Copy Markdown
Contributor Author

Yes im alright with this. So i remove the black checks from python-lint.yml and keep the type_hints.py check?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Github-files Github related files Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add type hints in python

3 participants