typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Add third-party lief stubs

Open chinggg opened this issue 3 years ago • 9 comments

Add the initial stubs for lief, generated by python3 scripts/create_baseline_stubs.py lief

Fix https://github.com/lief-project/LIEF/issues/650

These errors should be fixed before PR get merged.

Running black: black stubs/lief
error: cannot format stubs/lief/lief/MachO.pyi: Cannot parse: 40:6:     32BIT_BRANCH: ClassVar[ARM_RELOCATION] = ...
error: cannot format stubs/lief/lief/OAT.pyi: Cannot parse: 172:29:     def magic(self) -> Magic number: ...
error: cannot format stubs/lief/lief/__init__.pyi: Cannot parse: 215:15: class ItemsView[DictStringVersion]:
error: cannot format stubs/lief/lief/DEX.pyi: Cannot parse: 394:10: class lief.DEX.MapList.it_items_t:
error: cannot format stubs/lief/lief/ELF/__init__.pyi: Cannot parse: 455:35:     def eof_offset(self) -> Return the last offset used by the ELF binary according to both: ...
error: cannot format stubs/lief/lief/PE.pyi: Cannot parse: 1339:17:     machine: The target machine architecture
  • [ ] 32BIT_BRANCH starts with number, so it is not a valid identifier
  • [ ] Magic number contains space, not valid
  • [ ] class ItemsView[DictStringVersion] use [] when declaring custom class, not valid
  • [ ] class lief.DEX.MapList.it_items_t contains dots (.), not valid
  • [ ] eof_offset has wrong return type, which is more like comments
  • [ ] machine in PE.pyi has wrong type annotation, which contains space

chinggg avatar Jul 28 '22 01:07 chinggg

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

github-actions[bot] avatar Jul 28 '22 01:07 github-actions[bot]

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

github-actions[bot] avatar Jul 28 '22 03:07 github-actions[bot]

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

github-actions[bot] avatar Jul 29 '22 07:07 github-actions[bot]

@srittau Thanks for your help! These errors have shown some common patterns so I am trying to fix them in a reasonable way.

One thing that might help: Just send a PR with just the result of scripts/create_baseline_stubs.py and maybe a bit of import cleanup. We can then build on that.

The first commit https://github.com/python/typeshed/pull/8417/commits/f14343ea24968047c74f0e0e67774fa8d6727f5e is generated by scripts/create_baseline_stubs.py and it has many errors so I try to make a commit for each file to fix them. So you mean I just need the first commit and you can build on that without error automatically?

chinggg avatar Aug 08 '22 12:08 chinggg

Ah I see. The original commit indeed has lots of problems. Normally that script generates acceptable stubs, but not in this case, unfortunately. So please ignore my comment above.

But maybe the easiest solution in case of errors would be to just remove the problematic type annotation for now, if it is not an easy fix. This makes it easier for you to finish the stubs and for us to review the first version.

srittau avatar Aug 08 '22 12:08 srittau

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

github-actions[bot] avatar Aug 22 '22 05:08 github-actions[bot]

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

github-actions[bot] avatar Aug 28 '22 02:08 github-actions[bot]

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

github-actions[bot] avatar Aug 28 '22 13:08 github-actions[bot]

For now, most of my change is to convert C++ enum to Python enum since the auto script cannot express it using Python Enum class. I think this conversion should be achieved automatically in the future (will it be difficult?) since we cannot just rely on manual efforts to keep up with the latest change.

chinggg avatar Aug 28 '22 13:08 chinggg

Unfortunately there are many CI checks failing here, and I don't think any of us currently have the bandwidth to help this PR pass all of our CI :(

I'm going to close this PR for now due to lack of recent activity, and to keep our list of open PRs at a manageable level. But I'm happy to reopen it if you're still interested in working on it :)

AlexWaygood avatar Nov 30 '22 11:11 AlexWaygood