Make it so that mypy thinks that ParticleLike
has the same attributes as Particle
#2596
Labels
ParticleLike
has the same attributes as Particle
#2596
In functions decorated with
@particle_input
, arguments are converted from somethingParticleLike
into aParticle | CustomParticle | ParticleList
. When an attribute of the processed argument is used, mypy detects aunion-attr
error, such as inplasmapy.particles.atomic
. If we made mypy and static type checkers interpret thatParticleLike
had appropriate attributes, then we could avoid these mypy errors. All this applies toParticleListLike
too.The possibilities that I can think of that might work are:
.pyi
type stub file that overridesParticleLike
if typing.TYPE_CHECKING
block that adds the attributes toParticleLike
ParticleLike
(though this doesn't seem like a clean way to go about it).This probably requires some thought, and a better understanding of static type checking in Python. In the meantime, we should add
type: ignore[union-attr]
comments when this happens. (We probably don't want to disableunion-attr
checks entirely because they've helped me identify potential bugs.)The text was updated successfully, but these errors were encountered: