-
Notifications
You must be signed in to change notification settings - Fork 3
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
Adding type annotations #11
base: master
Are you sure you want to change the base?
Conversation
return "<int{}>".format(counter) | ||
|
||
def join_ns(*args): | ||
for arg in args: | ||
if arg == None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially tried to type this as returning Optional[str]
as per the original check here, which blew up into dozens of other places having to account for possible None. Then I removed this check, and I believe it is no longer necessary. Both MyPy and my own local testing suggests there's no situation in which an accidental None can make its way into this function.
self.fullns = fullns | ||
self.points_to = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bothered me quite a bit that a dictionary was getting created for every definition just to hold two different variables. Then the dictionary got in the way of correctly inferring the types of the two kinds of pointers and this is all cleaner now.
def visit_Call(self, node): | ||
logger.debug("In PreProcessor.visit_Call") | ||
def visit_Call(self, node: ast.Call): | ||
# logger.debug("In PreProcessor.visit_Call") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried not to include many unrelated typographical changes in this PR, but I cleaned up my work by running ruff format and the diffs were stuck together in a few of these.
@@ -128,16 +142,6 @@ def visit_For(self, node): | |||
super().visit_For(node) | |||
logger.debug("Exit PreProcessor.visit_For") | |||
|
|||
def visit_Return(self, node): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whole methods were duplicated, redefining the same name? I believe there's one more method redefinition in the project, but the two implementations are not the same, so I've left those be for now.
In the process of disentangling what's going on in PyCG, I found it helpful to add type annotations, which revealed a few issues, but also overall made it much easier to move through the project in VS Code. Will comment on specific highlights inline.