emehrkay / Pypher

Python Cypher Querybuilder
MIT License
164 stars 29 forks source link

.`len` prefix and suffix when constructing pypher query in Python Console #45

Closed f0r3n51c6uy closed 3 years ago

f0r3n51c6uy commented 3 years ago

I've tried to construct the example from the README.md in the Python Console and observed some strange prefix and suffix when converting the pypher object to a string. It seems that multiple .len terms are appended as prefix and suffix.

When executing the example instruction in a python script everything works as expected.

>>> from pypher import Pypher
>>> q = Pypher()
>>> q.Match.node('mark', labels='Person').WHERE.mark.property('name') == 'Mark'
<pypher.builder.Pypher object at 0x000002B3129C9AF0>
>>> q.RETURN.mark
<pypher.builder.Pypher object at 0x000002B3129C9AF0>
>>> str(q)
'.`len`.`len`.`len`.`len` MATCH MATCH (mark:`Person`) WHERE mark.`name` = $NEO_2361e_0.`len`.`len`.`len`.`len` RETURN RETURN mark.`len`.`len`.`len`.`len`'
>>> q.bound_params
OrderedDict([('NEO_2361e_0', 'Mark')])

system information:

emehrkay commented 3 years ago

This must be a windows issue. I have python 3.8.5 and it seems fine (on macOS). When I get in front of a windows machine I can debug a bit more. Can you reproduce this issue using the linux subsystem?

f0r3n51c6uy commented 3 years ago

I perform some test on different Windows 10 computers with PowerShell as Shell and Python 3.8.5 installed and I can't reproduce the error. In the initial issue I forget to mention that the strange behavior occurs in the Python IDE PyCharm (Community Edition) Version 2020.2.1. I tested the Version 2019.2.1 and the error doesn't occur.

After this testing I conclude that the error is created by the PyCharm IDE and not by the pypher package. If you agree with me we can close this Issue.

Have a nice day Dominic

emehrkay commented 3 years ago

Thanks for the bug report.

PyCharm must be doing something with object inspection that causes a .len call to be added to the chain. I wonder if it is possible to reproduce by simply defining a __len__ method on a class and having it print something to stdout.

I could see PyCharm's devs having the assumption that len() would not produce any side effects, I bet not many implementations of it does