typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Add stubs for pygit2

Open xen0n opened this issue 1 year ago • 8 comments

The upstream library is very tricky to type (likely requires nontrivial refactoring), and only contains partial type information, but stubs are a lot easier because only the public signatures are involved this way, so I plan to first make the library usable in typed projects by making stubs available here, then gradually work my way upstream.

The stubs are auto-generated then completed with fully manual inspection of every Python source file. The _pygit2.pyi comes from upstream and is mostly untouched except for required style changes, the signature of options(), and FilterSource which is missing from upstream.

xen0n avatar Feb 07 '24 10:02 xen0n

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

github-actions[bot] avatar Feb 07 '24 10:02 github-actions[bot]

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

github-actions[bot] avatar Feb 07 '24 10:02 github-actions[bot]

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

github-actions[bot] avatar Feb 07 '24 11:02 github-actions[bot]

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

github-actions[bot] avatar Feb 07 '24 11:02 github-actions[bot]

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

github-actions[bot] avatar Feb 07 '24 11:02 github-actions[bot]

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

github-actions[bot] avatar Feb 07 '24 11:02 github-actions[bot]

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

github-actions[bot] avatar Feb 08 '24 09:02 github-actions[bot]

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

github-actions[bot] avatar Feb 08 '24 10:02 github-actions[bot]

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

github-actions[bot] avatar Feb 28 '24 11:02 github-actions[bot]

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

github-actions[bot] avatar Feb 28 '24 12:02 github-actions[bot]

I've just removed all AnyStr_co occurrences and fixed the rest of signature mistakes pointed out in the review comments.

xen0n avatar Feb 28 '24 12:02 xen0n

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

github-actions[bot] avatar Feb 28 '24 12:02 github-actions[bot]

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

github-actions[bot] avatar Feb 28 '24 13:02 github-actions[bot]

It seems mypy cannot handle the re-import of Repository with different types if the star-imports have to be preserved in the stubs:

stubs/pygit2/pygit2/__init__.pyi:24: error: Incompatible import of "Repository" (imported name has type "type[pygit2.repository.Repository]", local name has type "type[pygit2._pygit2.Repository]")  [assignment]

xen0n avatar Feb 28 '24 13:02 xen0n

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

github-actions[bot] avatar Mar 02 '24 07:03 github-actions[bot]

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

github-actions[bot] avatar Mar 02 '24 08:03 github-actions[bot]

It seems simply ignoring the type check error on the Repository re-import doesn't work. When I was working on a project with the content of this PR integrated into its stubs/ I see Pylance failing to infer type for pygit2.Repository (saying the name doesn't exist).

xen0n avatar Mar 02 '24 08:03 xen0n