You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Additional context
I would like to write the above code as
returnSomeClass(...,token.line,token.column,...)
Using #type : ignore works but using a formatter like black sometimes put in the same line two assignations while creating a object, including one using a toke.line or similar and the type ignore would hide bugs in the other assignation (happened 3 times to me until now).
Particularly this can happen inside a transformer method.
I don't think this would affect the rest of the code and would like to submit a pr for this.
The text was updated successfully, but these errors were encountered:
The reason the signature is the way it is is because the line attributes might be None. If you want to write typesafe code, you will need to check for this. If you are checking for this and mypy can't figure out that you are doing the check, that would be a problem on mypy's side, not something we can fix.
I thought something like that, this particularly can happen if you inject tokens after the lexer stage. But if you are not injecting tokens, then you end with every function on a transformer following this pattern
When you know you are not injecting tokens, and if you are, you can explicitly state that you are generating tokens without information by using Token[None]
Suggestion
The current
Token
class has signature ofOptional[int]
for column, line and positions. This means that you always need toEven when we already know that tokens must have non
None
attribute.We can parameterize
Token
like:Describe alternatives you've considered
Until now this is forcing me to write
Additional context
I would like to write the above code as
Using
#type : ignore
works but using a formatter like black sometimes put in the same line two assignations while creating a object, including one using atoke.line
or similar and the type ignore would hide bugs in the other assignation (happened 3 times to me until now).Particularly this can happen inside a transformer method.
I don't think this would affect the rest of the code and would like to submit a pr for this.
The text was updated successfully, but these errors were encountered: