-
Notifications
You must be signed in to change notification settings - Fork 557
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
types: Add assert_never for exhaustivenes checking with mypy #839
Conversation
The code you added here is just what I had in mind for #835 - nice! However, mypy doesn't seem to be recognizing the narrowed types. The error around line 1200 is most clear: although we've handled all cases (file, function, bb), mypy is worried about the type |
ahh, for the
I found this by copying the example in the blog post and using |
I don't have edit permissions for your repo, so @Cl3o would you update this PR with the above changes? |
looking next at the other mypy error... |
Ahh, okay. I noticed those warnings from mypy too, and I wasn't sure if it was just on my end or not. Do you want me to just do a fixup for those errors real quick? |
doesn't matter either way, I was just trying to save you a step before tagging you to request the edit. |
Okay. I'll make the edit in a bit. |
for the other case, the checking of what we want is to have mypy do exhaustiveness checking on all the subtypes of here's the code as proposed above: elif isinstance(node, ceng.Statement):
# unhandled type of statement.
# this should only happen if a new subtype of `Statement`
# has since been added to capa.
#
# ideally, we'd like to use mypy for exhaustiveness checking
# for all the subtypes of `Statement`.
# but, as far as i can tell, mypy does not support this type
# of checking.
#
# in a way, this makes some intuitive sense:
# the set of subtypes of type A is unbounded,
# because any user might come along and create a new subtype B,
# so mypy can't reason about this set of types.
assert False, f'Unhandled value: {node} ({type(node).__name__})' @Cl3o if you agree, would you add this check? then, we'll be happy to merge! |
About the first change - I get a warning in PyCharm: |
I think that's everything. Thank you for being so patient with me. :) |
no, thank you! this looks great and it was easy to work with you. (no pressure) would you like to find or be recommended another capa issue? |
I'd love to work on another issue. Do you have anything specific in mind? |
here are a few issues that won't require a very deep knowledge of capa's internals. #430 feel free to assign yourself any of these and open a PR. also, we're happy to discuss the requirements more if its unclear what is needed. we'd like to make it as easy as possible for contributors, so let us know what we can do to make your task easier! |
I think I'll start with #331 and go from there. :) |
Sorry. I wasn't sure where to ask this, so I'm just writing it here. What does it mean to be invited as a collaborator? |
Ahh, okay. That's fine then. |
This PR addresses issue #835, and should help with exhaustiveness checking for types. Running
mypy capa/rules.py
showed no errors before I made these changes.Output of
mypy capa/rules.py
after change:Checklist