Enable a way to enforce the length of a `ParticleList` upon creation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 711
- Forks
- 375
- Avg merge
- 3h 2m
- Merged PRs (30d)
- 8
Description
Feature description
We should create a mechanism by which we can easily enforce the length of a ParticleList.
Motivation
When dealing with particle interactions, it's common to need to create a ParticleList of length two. Right now, it's necessary to add a couple of lines of code:
if len(particle_list) != 2:
raise ValueError("Add an error message here.")
This isn't so long, but we'd need to recreate the error message each time, so we'd end up with repeating code. Given how frequently this comes up, it'd be helpful to have a more standard error message and way of handling this situation.
Implementation strategy
This could be in ParticleList itself, via @particle_input(), or through the creation of a separate function.
If we do this via @particle_input(), we could use the new annotated typing capabilities. These are the capabilities that let us have annotations like u.Quantity[u.kg], and use the __class_getitem__ dunder, so it could be ParticleListLike[2]. Alternately, we could have a separate keyword argument in the signature of @particle_input().
When the length is
Additional context
Many thanks to @ejohnson-96 for originally discussing this idea with me!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ParticleList implementation and the @particle_input() entry point, since the issue proposes either location for enforcing length. Compare the possible approaches described, then define the behavior and standard error message for length-constrained ParticleList creation; the issue does not name a test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100