-
-
Notifications
You must be signed in to change notification settings - Fork 414
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
Tree.children annotated with str instead of Token #966
Comments
It should be |
Sure, I can write that up.
|
The basic idea is that Tree is a generic structure that can contain any kind of object. So it's actually wrong in the sense that it should be BUT, Trees produced by Lark do follow a Union[Tree, Token] limitation. We can express that in the return value of |
I played around with things and I think I have a solution that works by making A type alias could then makes it easy to work with trees that have One note, with the current situation of the annotations being in stub files, it is a little awkward. User code that wants to provide a type needs to quote the value because the actual class doesn't support square brackets. However, I say the notes on dropping Python 2 support and a draft PR that moves the annotations into the code base. That would make this current issue go away. |
Make a PR based on top of those changes and mark it as draft. If even we change those PRs even more, the core ideas will stay the same (e.g. no stub files). |
Can we say this issue is now solved? |
Yup |
Describe the bug
The type annotation for a
Tree
's children isUnion[str, Tree]
. However, the actual type isUnion[Token, Tree]
. While it is true thatToken
is astr
, it causesmypy
errors when trying to use Token properties.One possible explanation is that the library wants to obscure away the fact that the real type is
Token
and only consider it astr
. However, If I attempt to transform a parsed tree with the intent to write out a slightly altered file,Reconstructor
fails when it gets astr
instead of aToken
.To Reproduce
Example of
mypy
displaying an error for something that is valid.Using
lark
0.11.3 &mypy
0.910.Example of
Reconstructor
failure when replacing a token with astr
. (Onlymypy
error has to do with a different annotation error forreconstruct()
that has already been fixed.)The text was updated successfully, but these errors were encountered: