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
unify types for lib2to3.pytree.Base.children #78164
Comments
When type checking applications using lib2to3, the difference in types for lib2to3.pytree.Base.children versus Node.children makes it difficult to accept both leaves and nodes and programatically work with child nodes/leaves. Base/Leaf both have |
Empty list takes more memory and more time for creating than an empty tuple (the latter is just a singleton). Since all Node and Leaf instances share the same children by default, making it a list is errorprone. What is the problem of having an empty tuple instead of an empty list? |
The problem I'm trying to solve is around functions that operate on a Union[Leaf, Node], and want to be able to do things like re. error prone: Since the expectation in lib2to3 is already that fixers shouldn't be modifying |
Concatenating list and tuple (or tuple and list) you can write as: grandchildren = [*node.children[0].children, *node.children[1].children] The only list methods not available for tuples are mutating methods (using them with a shared empty list would be a bug), and copy() (a[:] and list(a) work with both lists and tuples). >>> sorted(set(dir(list)) - set(dir(tuple)))
['__delitem__', '__iadd__', '__imul__', '__reversed__', '__setitem__', 'append', 'clear', 'copy', 'extend', 'insert', 'pop', 'remove', 'reverse', 'sort'] |
Isn't children annotated as List in typeshed? |
Yes, lib2to3.pytree.Base.children is annotated as a list of (Node or Leafs) |
lib2to3 is deprecated as of Python 3.11, and there's an available workaround. I don't think it still makes sense to change anything here. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: