ParticleListLike

plasmapy.particles.particle_collections.ParticleListLike: TypeAlias = plasmapy.particles.particle_collections.ParticleList | collections.abc.Sequence[str | int | numpy.integer | plasmapy.particles.particle_class.Particle | plasmapy.particles.particle_class.CustomParticle | astropy.units.quantity.Quantity]

An object is particle-list-like if it can be identified as a ParticleList or cast into one.

When used as a type annotation, ParticleListLike indicates that the corresponding argument should represent a sequence of physical particles. Each item in a ParticleListLike object must be particle-like.

Notes

DimensionlessParticle instances do not uniquely represent a physical particle, and are thus not ParticleLike and cannot be contained in a ParticleListLike object.

Examples

Using ParticleListLike as a type annotation indicates that an argument or variable should represent a sequence of ParticleLike objects.

>>> from plasmapy.particles import ParticleList, ParticleListLike
>>> def contains_only_leptons(particles: ParticleListLike):
...     particle_list = ParticleList(particles)
...     return all(particle_list.is_category("lepton"))
>>> contains_only_leptons(["electron", "muon"])
True