You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add type hints to timeout, term.text, hashes, and more (#2723)
* Add typehints to timeout module
Co-authored-by: Copilot <copilot@github.com>
* Add typehints to device class
* Add typehints to PwnlibException
* Add general typehints for term.text module
Since the available module attributes are handled dynamically like `text.green()` or `text.green_on_white()` or `text.underline_red()`, it's not feasible to type out all possible combinations.
Just tell the type checker that all module attibutes have the same type and thus avoid the `error: Module has no attribute "bold_blue" [attr-defined]` errors.
* Add typehints for config module
* Add typehints for hashes module
The guaranteed algorithms in hashlib are pretty stable and we can generate the list out proper type checking and auto complete.
Still add a check in CI that notifies us if there are changes in the future.
* Add atexception and atexit types
atexception.unregister was not documented correctly since the function expects an identifier returned by `atexception.register` instead of the handler function.
* Fix toplevel type hints in shellcraft.internal
* Fix toplevel type hints in term.key
---------
Co-authored-by: Copilot <copilot@github.com>
Copy file name to clipboardExpand all lines: mypy-baseline.txt
+1-29Lines changed: 1 addition & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,7 @@ pwn/toplevel.py:0: error: Incompatible import of "size" (imported name has type
4
4
pwn/toplevel.py:0: error: Incompatible import of "size" (imported name has type "Callable[[Any, Any, Any], Any]", local name has type "str") [assignment]
5
5
pwn/toplevel.py:0: error: Incompatible import of "size" (imported name has type "int", local name has type "str") [assignment]
6
6
pwnlib/abi.py:0: error: Need type annotation for "register_arguments" (hint: "register_arguments: list[<type>] = ...") [var-annotated]
7
-
pwnlib/asm.py:0: error: Module "pwnlib.util.hashes" has no attribute "sha1sumhex" [attr-defined]
8
7
pwnlib/asm.py:0: error: Need type annotation for "util_versions" [var-annotated]
9
-
pwnlib/atexception.py:0: error: Function "_run_handlers" could always be true in boolean context [truthy-function]
10
8
pwnlib/commandline/cyclic.py:0: error: "Callable[[Any, Any, Any, Any], Any]" has no attribute "add_argument" [attr-defined]
11
9
pwnlib/commandline/cyclic.py:0: error: "Callable[[Any, Any, Any, Any], Any]" has no attribute "add_argument" [attr-defined]
12
10
pwnlib/commandline/cyclic.py:0: error: Incompatible types in assignment (expression has type "_MutuallyExclusiveGroup", variable has type "Callable[[Any, Any, Any, Any], Any]") [assignment]
@@ -37,21 +35,6 @@ pwnlib/filesystem/path.py:0: error: "classmethod" used with a non-method [misc]
37
35
pwnlib/filesystem/path.py:0: error: "type[Path]" has no attribute "mkdtemp" [attr-defined]
38
36
pwnlib/filesystem/path.py:0: error: "type[Path]" has no attribute "mktemp" [attr-defined]
39
37
pwnlib/gdb_api_bridge.py:0: error: Name "socket_path" is not defined [name-defined]
40
-
pwnlib/libcdb.py:0: error: Module "pwnlib.util.hashes" has no attribute "md5filehex" [attr-defined]
41
-
pwnlib/libcdb.py:0: error: Module "pwnlib.util.hashes" has no attribute "sha1filehex" [attr-defined]
42
-
pwnlib/libcdb.py:0: error: Module "pwnlib.util.hashes" has no attribute "sha256filehex" [attr-defined]
43
-
pwnlib/log.py:0: error: Module has no attribute "bold_blue" [attr-defined]
44
-
pwnlib/log.py:0: error: Module has no attribute "bold_blue" [attr-defined]
45
-
pwnlib/log.py:0: error: Module has no attribute "bold_blue" [attr-defined]
46
-
pwnlib/log.py:0: error: Module has no attribute "bold_green" [attr-defined]
47
-
pwnlib/log.py:0: error: Module has no attribute "bold_red" [attr-defined]
48
-
pwnlib/log.py:0: error: Module has no attribute "bold_red" [attr-defined]
49
-
pwnlib/log.py:0: error: Module has no attribute "bold_yellow" [attr-defined]
50
-
pwnlib/log.py:0: error: Module has no attribute "bold_yellow" [attr-defined]
51
-
pwnlib/log.py:0: error: Module has no attribute "magenta" [attr-defined]
52
-
pwnlib/log.py:0: error: Module has no attribute "on_red" [attr-defined]
53
-
pwnlib/log.py:0: error: Module has no attribute "on_red" [attr-defined]
54
-
pwnlib/log.py:0: error: Module has no attribute "on_red" [attr-defined]
55
38
pwnlib/log.py:0: error: Need type annotation for "_one_time_infos" (hint: "_one_time_infos: set[<type>] = ...") [var-annotated]
56
39
pwnlib/log.py:0: error: Need type annotation for "_one_time_warnings" (hint: "_one_time_warnings: set[<type>] = ...") [var-annotated]
57
40
pwnlib/memleak.py:0: error: Module "pwnlib.util.packing" has no attribute "_p8lu" [attr-defined]
@@ -86,22 +69,11 @@ pwnlib/shellcraft/__init__.py:0: error: Argument 1 to "append" of "list" has inc
86
69
pwnlib/shellcraft/__init__.py:0: error: Need type annotation for "_templates" (hint: "_templates: list[<type>] = ...") [var-annotated]
87
70
pwnlib/term/__init__.py:0: error: Module has no attribute "height" [attr-defined]
88
71
pwnlib/term/__init__.py:0: error: Module has no attribute "width" [attr-defined]
89
-
pwnlib/term/key.py:0: error: Need type annotation for "_kbuf" (hint: "_kbuf: list[<type>] = ...") [var-annotated]
90
-
pwnlib/term/readline.py:0: error: Module has no attribute "reverse" [attr-defined]
91
72
pwnlib/term/readline.py:0: error: Need type annotation for "history" (hint: "history: list[<type>] = ...") [var-annotated]
92
73
pwnlib/term/readline.py:0: error: Need type annotation for "search_results" (hint: "search_results: list[<type>] = ...") [var-annotated]
93
74
pwnlib/term/term.py:0: error: Need type annotation for "on_winch" (hint: "on_winch: list[<type>] = ...") [var-annotated]
75
+
pwnlib/timeout.py:0: error: Incompatible return value type (got "float | TimeoutDefault", expected "float") [return-value]
94
76
pwnlib/tubes/process.py:0: error: Cannot assign to a type [misc]
95
77
pwnlib/tubes/process.py:0: error: Incompatible types in assignment (expression has type "PTY", variable has type "type[PTY]") [assignment]
96
-
pwnlib/tubes/process.py:0: error: Module "pwnlib.util.hashes" has no attribute "sha256file" [attr-defined]
97
78
pwnlib/tubes/tube.py:0: error: Argument 1 to "make_wrapper" has incompatible type "function"; expected "tube" [arg-type]
98
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "blue" [attr-defined]
99
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "blue" [attr-defined]
100
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "gray" [attr-defined]
101
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "gray" [attr-defined]
102
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "green" [attr-defined]
103
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "has_gray" [attr-defined]
104
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "has_gray" [attr-defined]
105
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "red" [attr-defined]
106
-
pwnlib/util/fiddling.py:0: error: Module has no attribute "red" [attr-defined]
107
79
pwnlib/util/iters.py:0: error: Name "pairwise" already defined (possibly by an import) [no-redef]
0 commit comments