[issue33983] unify types for lib2to3.pytree.Base.children

2022-01-23 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

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.

--
nosy: +Jelle Zijlstra
resolution:  -> wont fix
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33983] unify types for lib2to3.pytree.Base.children

2020-02-14 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:

> Isn't children annotated as List in typeshed?

Yes, lib2to3.pytree.Base.children is annotated as a list of (Node or Leafs)
https://github.com/python/typeshed/blob/ea0a9c2bd6f6a69c3e49b47870e0109d98316fc6/stdlib/2and3/lib2to3/pytree.pyi#L23

--
nosy: +BTaskaya

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33983] unify types for lib2to3.pytree.Base.children

2019-09-11 Thread Benjamin Peterson


Benjamin Peterson  added the comment:

Isn't children annotated as List in typeshed?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33983] unify types for lib2to3.pytree.Base.children

2018-06-28 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

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']

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33983] unify types for lib2to3.pytree.Base.children

2018-06-28 Thread John Reese


John Reese  added the comment:

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 `grandchildren = 
node.children[0].children + node.children[1].children` (contrived example, but 
point being tuple+list=TypeError while list+tuple=OK).  There are similar cases 
around list methods not being available for tuples.  In both cases, as is, the 
function needs to do some amount of type checking at runtime of each child to 
determine what operations can be done.  Also, IMO, from a type annotation 
perspective, having a child class that uses a different type for an attribute 
from the base class is an anti-pattern, or weird at best.

re. error prone:  Since the expectation in lib2to3 is already that fixers 
shouldn't be modifying `node.children` directly, I don't see how this makes 
anything more error prone.  Base/Leaf objects lack those methods for 
modifications, so unless the code is already being a bad actor, the situation 
isn't changed.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33983] unify types for lib2to3.pytree.Base.children

2018-06-28 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

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?

--
nosy: +benjamin.peterson, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33983] unify types for lib2to3.pytree.Base.children

2018-06-27 Thread John Reese


Change by John Reese :


--
keywords: +patch
pull_requests: +7588
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33983] unify types for lib2to3.pytree.Base.children

2018-06-27 Thread John Reese


New submission from John Reese :

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 `children` defined as an empty Tuple, while Node defines it 
as an empty list.  It would be more useful for Base/Leaf to also use an empty 
list, so that the type is the same, regardless of which type of object you are 
given.

--
components: Library (Lib)
messages: 320616
nosy: jreese, lukasz.langa
priority: normal
severity: normal
status: open
title: unify types for lib2to3.pytree.Base.children
type: enhancement
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com