Skip to content

Add Type Annotations for parts of pwnlib/util#2679

Open
SmoothHacker wants to merge 7 commits intoGallopsled:devfrom
SmoothHacker:fix-pwnlib-util-type-annotations
Open

Add Type Annotations for parts of pwnlib/util#2679
SmoothHacker wants to merge 7 commits intoGallopsled:devfrom
SmoothHacker:fix-pwnlib-util-type-annotations

Conversation

@SmoothHacker
Copy link

I used ruff to flag areas of pwnlib/util that are missing type annotations. This is what I have done so far. If this looks good then I can proceed with other parts of the code base.

@RocketMaDev
Copy link
Contributor

Should type annotations be added to docs? So user can know arg types when reading documentation.

@Arusekk
Copy link
Member

Arusekk commented Feb 20, 2026

I believe the type hints can be made a bit modular, this would require some thought.

For one, I think we use a lot of bytes|bytearray|memoryview. There should already be a stdlib type (BytesLike?) for that. We also use a lot of BytesLike|str (maybe call it Ascii? There are many places where only valid chars/codepoints are indeed ascii). Try to look for other examples of commonly appearing nontrivial types and add them e.g. to a new module called pwntools._typehints or pwntools.typing etc. Try to look at other well typed Python projects for inspiration.

@SmoothHacker
Copy link
Author

Should type annotations be added to docs? So user can know arg types when reading documentation.

There should be a way to configure readthedocs to incorporate the type hints. I can look into that quickly.

I believe the type hints can be made a bit modular, this would require some thought.

For one, I think we use a lot of bytes|bytearray|memoryview. There should already be a stdlib type (BytesLike?) for that. We also use a lot of BytesLike|str (maybe call it Ascii? There are many places where only valid chars/codepoints are indeed ascii). Try to look for other examples of commonly appearing nontrivial types and add them e.g. to a new module called pwntools._typehints or pwntools.typing etc. Try to look at other well typed Python projects for inspiration.

I can make the longer type hints more neater with "super types" like BytesLike or AsciiLike as you described

@SmoothHacker SmoothHacker force-pushed the fix-pwnlib-util-type-annotations branch 2 times, most recently from 4e75d36 to f5b83af Compare February 21, 2026 15:49
@RocketMaDev
Copy link
Contributor

Should type annotations be added to docs? So user can know arg types when reading documentation.

There should be a way to configure readthedocs to incorporate the type hints. I can look into that quickly.

I found that sphinx will automatically extract function signature with type hints, without explicitly write it in doc string. Never mind.

@SmoothHacker SmoothHacker force-pushed the fix-pwnlib-util-type-annotations branch from e66825a to b8b3bb2 Compare March 1, 2026 00:57
@SmoothHacker
Copy link
Author

@RocketMaDev this PR should be ready to go

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.

3 participants