Skip to content
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

system.part.by_id() accepts bool arguments #4990

Open
pm-blanco opened this issue Sep 4, 2024 · 0 comments
Open

system.part.by_id() accepts bool arguments #4990

pm-blanco opened this issue Sep 4, 2024 · 0 comments

Comments

@pm-blanco
Copy link
Contributor

While debugging a code I found an interesting behavior in espresso. It seems that system.part.by_id() accepts bool variables as input arguments:

import espressomd
system = espressomd.System(box_l=[2]*3)
part = system.part.by_id(False)
print(part.id)
>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "particle_data.pyx", line 107, in espressomd.particle_data.ParticleHandle.id.__get__
  File "particle_data.pyx", line 55, in espressomd.particle_data.ParticleHandle.update_particle_data
RuntimeError: Particle node for id 0 not found!

In this situation, I would intuitively expect to get a TypeError message but instead it seems that espresso automatically transforms my bool argument to 0. In a way, it is kind of expected because False in Python is used as a keyword for 0 but I can imagine that it could become a source of bugs for people with more basic knowledge of Python. I let you to decide if this a bug or a feature of espresso, although I think that it would be generally better to restrict the accepted variable types to avoid unexpected behaviors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant