jeetsukumaran / DendroPy

A Python library for phylogenetic scripting, simulation, data processing and manipulation.
https://pypi.org/project/DendroPy/.
BSD 3-Clause "New" or "Revised" License
210 stars 61 forks source link

Calling tab complete on a tree surpresses unifurcations in Python 3.7.3 #141

Closed emilydolson closed 6 months ago

emilydolson commented 2 years ago

I know this sounds really strange, but using tab complete (in the interactive python interpreter) appears to alter the internal state of Dendropy Tree objects. Specifically, it seems to remove all unifurcations.

Here's a simple example (>>> lines are code I executed, other lines are the stdout response):

>>> import dendropy
>>> n1 = dendropy.Node(label="A")
>>> n2 = dendropy.Node(label="B")
>>> n3 = dendropy.Node(label="C")
>>> n1.add_child(n2)
<Node object at 0x7fa2bdaaf400: 'B' (None)>
>>> n2.add_child(n3)
<Node object at 0x7fa2bdaba208: 'C' (None)>
>>> t = dendropy.Tree(seed_node=n1)
>>> t.nodes()
[<Node object at 0x7fa2bdaaf470: 'A' (None)>, <Node object at 0x7fa2bdaaf400: 'B' (None)>, <Node object at 0x7fa2bdaba208: 'C' (None)>]
>>> t.  # Hit tab key here
Display all 150 possibilities? (y or n)
>>> t.nodes()
[<Node object at 0x7fa2bdaba208: 'C' (None)>]

I am using dendropy version 4.5.2 and Python 3.7.3.

It seems that this may be fixed with newer versions of Python (it doesn't seem to happen with Python 3.9), so I'm not sure how urgent it is to fix, but it was sufficiently baffling that I at least wanted to leave a record of it somewhere where others having the same problem could find it.

mmore500 commented 6 months ago

It looks like this is related to the actions of, which is calling getattr on various parts of the tree. https://docs.python.org/3/library/rlcompleter.html. Was able to reporduce for Python 3.8 and 3.7. Looks like behavior has changed in Python 3.9 onwards. Closing this as wontfix for now, but glad to have it documented somewhere!