trailofbits/deepstate

Support static type checking for Python codebase

ex0dus-0x opened this issue · 10 comments

Since we support much more modern Python 3.x builds, we should use static type checking with our Python codebases. By making our types explicit and more absolute, this should not only improve code clarity, but also reduce any runtime TypeErrors (or any other type-related exceptions) that may happen as a result of having looser typing.

Pyre and mypy are good third-party type checking frameworks to integrate, but we should first start with adding support for type hints with Python's native typing package.

Could i take a crack at this? I do static typing a lot and I think I could knock this out pretty fast

Sure!

There is some initial work I was playing around with on the py3-static-types branch. Feel free to pull and work off what has been done in bin/deepstate/frontend/frontend.py for the rest of the Python codebase. I used mypy to type check and optimize accordingly.

okay, i'm starting this for hacktoberfest but I am not sure if it'll be finished in the next few days so apologies if i'm slow!

also @ex0dus-0x, whats the scope of this mr? Should I go after every .py file i find or should I limit it to some part of the code base?

It's up to you to determine what should be integrated with static checking, since there's actually quite a lot of Python code that has evolved in the repo. However, some of my initial work being done for the core fuzzer frontend API is in bin/deepstate/frontend, which is a submodule that has been integrated quite recently, so that could be a good ideal starting place for implementation.

Gotcha, I'll go after it. I usually only add type hints where it's not obvious what a value is, traditionally only in the prototype of the function. Do you explicitly want type hints in the local variables as well?

I think having explicit type hints everywhere (even in the most obvious places) would work well with a static checker in regards to finding any low-hanging type-related issues that may arise during runtime.

@ex0dus-0x Do you still need this worked on?

Yes! Did a pass of type checking with mypy on our core frontend API, in anticipation of refactoring and adding new features. Feel free to approach this on any of our executors for fuzzing/symbolic execution!

Also be wary of organizational changes to upstream that may break changes you make in the upcoming week

Awesome, I'll hit it up this week