-
-
Notifications
You must be signed in to change notification settings - Fork 245
WIP: Adding type hints to formatter.py #947
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #947 +/- ##
==========================================
- Coverage 68.75% 68.75% -0.01%
==========================================
Files 63 63
Lines 9437 9440 +3
==========================================
+ Hits 6488 6490 +2
- Misses 2949 2950 +1
Continue to review full report at Codecov.
|
New to this - should I reformat formatter.py with black and resubmit the code? |
Looks like you got it, thank you! Sorry for the delay here.
I like the second one better, that seems truer to the code as it's currently written. Feel free to change the code though if it's easier to type, e.g. using a new temp variable or adding a new "if t is None" bailout. |
Thanks, @thomasballinger. I think the only way to avoid using At least, that's how it seems to me. I'll try another commit with a temp variable and you can make the call. I'm probably using too much of your time on the little details, but I appreciate the help! |
@thomasballinger, is there anything else I need to do with this PR at this point? |
Sorry about the delay, pinging with that comment was the perfect action. I'll look into this more this morning, right now when I run mypy locally I'm getting
which I'm sure it just my problem since it works in CI. Once I get this sorted (no action needed from you) I'll merge this. |
I have to change the typing of
I could imagine a reason for this: according to the types, it's not safe to include both |
Merged, thank you @Ben-Reg! |
Adding type hints to formatter.py.
A note on line 128.
token = token.parent
causes some problems with mypy becausetoken
is type_TokenType
whiletoken.parent
isOptional[_TokenType]
The easy solution that I used below was to type
tokensource
like so:tokensource: Iterable[MutableMapping[Any, str]]
Another approach would be something like this:
t: Optional[_TokenType] = token
t = t.parent
If we do it that way, we can type
tokensource
more accurately:tokensource: Iterable[MutableMapping[_TokenType, str]]