Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix + improve python type stubs #1386

Open
wants to merge 2 commits into
base: dev-v1.0
Choose a base branch
from

Conversation

Toizi
Copy link
Contributor

@Toizi Toizi commented Jan 11, 2025

There were a lot of errors in the generated type stub file due to invalid assignments from the namespace generation and type errors using the self.org forward approach. The stub file now uses enums to deal with the namespaces and only sets the docstring and type information in the functions.

The new code now also tries to handle overloads by merging functions since overloads with the same name are not allowed, e.g.

    def disassembly(self, inst):
        # type: (Instruction) -> None
        """Disassembles the instruction and sets up operands."""
        return self.org.disassembly(inst)


    def disassembly(self, block, addr=0):
        # type: (BasicBlock, int) -> None
        """Disassembles a basic block with a potential given base address."""
        return self.org.disassembly(block, addr=0)


    def disassembly(self, addr, count):
        # type: (int, int) -> List[Instruction]
        """Disassembles a concrete memory area from `addr` and returns a list of at most `count` disassembled instructions."""
        return self.org.disassembly(addr, count)


    def disassembly(self, addr):
        # type: (int) -> BasicBlock
        """Disassembles a concrete memory area from `addr` to control flow instruction and returns a BasicBlock."""
        return self.org.disassembly(addr)

turned into

    def disassembly(self, block_inst_addr, addr_count):
        # type: (Self, int | BasicBlock | Instruction, int) -> None
        """Disassembles the instruction and sets up operands.

Disassembles a basic block with a potential given base address.

Disassembles a concrete memory area from `addr` and returns a list of at most `count` disassembled instructions.

Disassembles a concrete memory area from `addr` to control flow instruction and returns a BasicBlock."""
        pass

This is not always a perfect solution depending on the overloads. From what I have seen it is basically always better than having just one because the others are ignored though.

Attached is the generated stub file in case you want to compare it to the current one. Just rename it to .pyi since github does not allow arbitrary file extensions.
triton.txt

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.

1 participant