-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Type annotations for RDA and other analysis related code #3023
Conversation
3544a3f
to
9dc8004
Compare
So obvi we need to get CI passing, both lint and the testcase that seems to be failing because of the changes (I will not pretend to understand what's going on there), but beyond that, can you provide some sort of metric to indicate that the types you added are correct? Just any static analysis result that indicates the typing coverage has gone up or the number of type errors has gone down? |
My current solution for the A metric for the improvement is an interesting question, my main reason for writing the annotations in the first place was that it made it easier to work with the code in PyCharm, i.e. better type inference (and especially reducing false positives for some types) and fixing some lint issues PyCharm complains about by default. I'll look into setting up a mypy config that primarily detects wrong type annotations, so we can at least know if some type annotation leads to inconsistencies. |
f65c81c
to
e17bae4
Compare
e17bae4
to
b79d2b4
Compare
@rhelmot now the only linting issue (and CI failure at all) left is:
which seems llike a bug in PyLint pylint-dev/pylint#3505 |
Alright - I'll take you at your word that this is an improvement. You should collaborate with @twizmwazin (kevin phoenix on slack) on getting the mypy pass set up in CI! |
Thanks a lot for the PR! I love seeing to add type annotations improving both ide experience and making closer typechecking with mypy As side notes: Am I the only one who’s slightly concerned with
|
@ulugbekna you raise some valid points:
kinda valid, I actually don't make a conscious decision for that and just assumed that the linter would complain if it is something that was deemed relevant...
Overall, how concerned are you? I am not sure if those are slight stylistic things, or if there are more severe implications I am missing. Probably not for single vs double quotes, but maybe for the quoted vs unquoted types. |
I’m afraid I’m not expert either. Development can happen incrementally so
this PR is definitely a good step forward :-)
…On Tue, 21 Dec 2021 at 22:55, Florian Magin ***@***.***> wrote:
@ulugbekna <https://github.com/ulugbekna> you raise some valid points:
The PR diverging from the common style of using single quotes by using
double quotes?
kinda valid, I actually don't make a conscious decision for that and just
assumed that the linter would complain if it is something that was deemed
relevant...
Also it seemed slightly inconsistent in using commented type annotations
vs ordinary type annotations, ie f(x: ‘int’) vs f(x: int)
the uncommented version isn't always possible due to possible import
cycles. I am not sure if the recommendation would be to always use the
quoted version, so far I basically use unquoted if possible (i.e. the types
are already available at runtime) or quoted if this isn't easily possible
for one of the various reasons.
Overall, how concerned are you? I am not sure if those are slight
stylistic things, or if there are more severe implications I am missing.
Probably not for single vs double quotes, but maybe for the quoted vs
unquoted types.
—
Reply to this email directly, view it on GitHub
<#3023 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD4YR6YEAL5KPNASJGEFSE3USDZTZANCNFSM5KIRCIEA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Lots of type annotations and fixups for various analysis related concepts and specifically the RDA.
Some of the annotations like 5a3b2cd might seem nearly useless, but they allow the IDE to infer that some access to this plugin is definitely of the type
SimStateJNIReferences
and methods/attributes that are the same as another class don't show up when searching for references to that member for the other class. All the annotations ofnetworkx.DiGraph
usage also serve this purpose, because often angr classes will have some member calledsuccessors
which has a totally different meaning thanDiGraph.successors
.Without annotations PyCharm can't realize that
graph.successors
is not a case whereSimProcedure.successors
is used, becausegraph
might technically be of the typeSimProcedure
.I am not sure how large the performance impact is to use exception based handling for the function handler. Instead of using
hasattr
. The massive issue with thehasattr
/getattr
approach is that it completely destroys the IDE analysis, and now it is at least possible to find every usage ofFunctionHandler.handle_external_function
and reason about the problem, instead of having to search the entire codebase for the string"handle_external_function"