Skip to content

[yara-python] Add yara-python stubs - #16509

Open
zeevro wants to merge 1 commit into
python:mainfrom
zeevro:yara-python
Open

zeevro wants to merge 1 commit into
python:mainfrom
zeevro:yara-python

Conversation

@zeevro

@zeevro zeevro commented Oct 12, 2026

Copy link
Copy Markdown

No description provided.

@github-actions

This comment has been minimized.

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

I don't think the match overloads are correct here: This would allow calls such as ...match(123) (where 123 is a PID), which wouldn't work at runtime. Also technically calls such as ...match("/path", -1, None) should work and I suggest to allow this in stubs as well. Please see my suggestions below. The alternative is to use * to mark arguments as kw-only.

Also, callbacks where the return value is ignored should use object as return type, not Any. Otherwise, as Any types must be explained, the return type must be explained in a comment.

Comment thread stubs/yara-python/yara.pyi
Comment thread stubs/yara-python/yara.pyi
Comment thread stubs/yara-python/yara.pyi
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@zeevro

zeevro commented Oct 18, 2026

Copy link
Copy Markdown
Author

I fixed the Rules.match trio and applied a somewhat similar treatment to the compile overloads. compile doesn't accept more that one of the "source" arguments, while Rules.match accepts at-least one, so they're a bit different. The compile overloads still don't represent the C source entirely accurately, because of the missing keywords for filepath, source, file, filepaths and sources. However, since most users will be using only keyword arguments I feel it's more important to convey the restriction of only one of these arguments being present. Is there a way to annotate a keyword-argument that must not be present? (Adding | None = None here will not work since the c source declares them O and checks for == NULL so None will fail that 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants