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

Improve type hint annotations to plasmapy.particles #2458

Merged
merged 18 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ untitled*
.DS_Store
*/cython_version.py
.mypy_cache
monkeytype.sqlite3
node_modules
package-lock.json
12 changes: 0 additions & 12 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,6 @@ disable_error_code = arg-type,assignment,call-overload,no-any-return,no-untyped-
[mypy-plasmapy.particles._special_particles]
disable_error_code = type-arg,var-annotated

[mypy-plasmapy.particles.atomic]
disable_error_code = arg-type,assignment,misc,no-any-return,no-untyped-call,no-untyped-def,union-attr

[mypy-plasmapy.particles.ionization_state]
disable_error_code = arg-type,assignment,call-overload,misc,no-any-return,no-untyped-call,no-untyped-def,operator,return-value,type-arg

Expand All @@ -335,9 +332,6 @@ disable_error_code = arg-type,assignment,has-type,index,misc,no-any-return,no-un
[mypy-plasmapy.particles.nuclear]
disable_error_code = misc,no-untyped-def,union-attr

[mypy-plasmapy.particles.particle_class]
disable_error_code = arg-type,assignment,attr-defined,has-type,index,misc,no-any-return,no-redef,no-untyped-def,return-value,type-arg,valid-type,var-annotated

[mypy-plasmapy.particles.particle_collections]
disable_error_code = no-any-return,no-untyped-call,no-untyped-def,override,type-arg,valid-type,var-annotated

Expand All @@ -350,9 +344,6 @@ disable_error_code = return-value
[mypy-plasmapy.particles.tests.conftest]
disable_error_code = attr-defined,no-untyped-def

[mypy-plasmapy.particles.tests.test_atomic]
disable_error_code = arg-type,attr-defined,no-untyped-def

[mypy-plasmapy.particles.tests.test_exceptions]
disable_error_code = attr-defined,no-untyped-def,operator,var-annotated

Expand All @@ -371,9 +362,6 @@ disable_error_code = attr-defined,no-untyped-def
[mypy-plasmapy.particles.tests.test_parsing]
disable_error_code = attr-defined,no-untyped-def

[mypy-plasmapy.particles.tests.test_particle_class]
disable_error_code = arg-type,attr-defined,no-untyped-call,no-untyped-def

[mypy-plasmapy.particles.tests.test_particle_collections]
disable_error_code = arg-type,no-untyped-call,no-untyped-def

Expand Down
43 changes: 22 additions & 21 deletions plasmapy/particles/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


@particle_input
def atomic_number(element: Particle) -> Integral:
def atomic_number(element: ParticleLike) -> int:
"""
Return the number of protons in an atom, isotope, or ion.

Expand Down Expand Up @@ -85,7 +85,7 @@ def atomic_number(element: Particle) -> Integral:


@particle_input
def mass_number(isotope: Particle) -> Integral:
def mass_number(isotope: ParticleLike) -> int:
"""Get the mass number (the number of protons and neutrons) of an
isotope.

Expand Down Expand Up @@ -127,7 +127,7 @@ def mass_number(isotope: Particle) -> Integral:


@particle_input(exclude={"isotope", "ion"})
def standard_atomic_weight(element: Particle) -> u.Quantity[u.kg]:
def standard_atomic_weight(element: ParticleLike) -> u.Quantity[u.kg]:
"""Return the standard (conventional) atomic weight of an element
based on the relative abundances of isotopes in terrestrial
environments.
Expand Down Expand Up @@ -185,10 +185,10 @@ def standard_atomic_weight(element: Particle) -> u.Quantity[u.kg]:

@particle_input(exclude={"neutrino", "antineutrino"})
def particle_mass(
particle: Particle,
particle: ParticleLike,
*,
mass_numb: Optional[Integral] = None,
Z: Optional[Integral] = None,
mass_numb: Optional[int] = None,
Z: Optional[float] = None,
) -> u.Quantity[u.kg]:
"""
Return the mass of a particle.
Expand Down Expand Up @@ -238,7 +238,7 @@ def particle_mass(


@particle_input
def isotopic_abundance(isotope: Particle, mass_numb: Optional[Integral] = None) -> Real:
def isotopic_abundance(isotope: ParticleLike, mass_numb: Optional[int] = None) -> Real:
"""
Return the isotopic abundances if known, and otherwise zero.

Expand Down Expand Up @@ -285,7 +285,7 @@ def isotopic_abundance(isotope: Particle, mass_numb: Optional[Integral] = None)


@particle_input(any_of={"charged", "uncharged"})
def charge_number(particle: Particle) -> Integral:
def charge_number(particle: ParticleLike) -> int:
"""Return the charge number of a particle.

Parameters
Expand Down Expand Up @@ -339,7 +339,7 @@ def charge_number(particle: Particle) -> Integral:


@particle_input(any_of={"charged", "uncharged"})
def electric_charge(particle: Particle) -> u.Quantity[u.C]:
def electric_charge(particle: ParticleLike) -> u.Quantity[u.C]:
"""
Return the electric charge (in coulombs) of a particle.

Expand Down Expand Up @@ -393,7 +393,7 @@ def electric_charge(particle: Particle) -> u.Quantity[u.C]:


@particle_input
def is_stable(particle: Particle, mass_numb: Optional[Integral] = None) -> bool:
def is_stable(particle: ParticleLike, mass_numb: Optional[int] = None) -> bool:
"""
Return `True` for stable isotopes and particles and `False` for
unstable isotopes.
Expand Down Expand Up @@ -444,7 +444,7 @@ def is_stable(particle: Particle, mass_numb: Optional[Integral] = None) -> bool:

@particle_input(any_of={"stable", "unstable", "isotope"})
def half_life(
particle: Particle, mass_numb: Optional[Integral] = None
particle: ParticleLike, mass_numb: Optional[int] = None
) -> u.Quantity[u.s]:
"""
Return the half-life in seconds for unstable isotopes and particles,
Expand Down Expand Up @@ -495,7 +495,7 @@ def half_life(
return particle.half_life


def known_isotopes(argument: Optional[Union[str, Integral]] = None) -> list[str]:
def known_isotopes(argument: Optional[Union[str, int]] = None) -> list[str]:
"""
Return a list of all known isotopes of an element, or a list of all
known isotopes of every element if no input is provided.
Expand Down Expand Up @@ -586,7 +586,7 @@ def known_isotopes_for_element(argument):


def common_isotopes(
argument: Optional[Union[str, Integral]] = None, most_common_only: bool = False
argument: Optional[Union[str, int]] = None, most_common_only: bool = False
) -> list[str]:
"""
Return a list of isotopes of an element with an isotopic abundances
Expand Down Expand Up @@ -806,7 +806,8 @@ def stable_isotopes_for_element(
@particle_input
@validate_quantities
def reduced_mass(
test_particle: ParticleLike, target_particle: ParticleLike
test_particle: ParticleLike,
target_particle: ParticleLike,
) -> u.Quantity[u.kg]:
r"""
Find the :wikipedia:`reduced mass` between two particles.
Expand Down Expand Up @@ -869,7 +870,7 @@ def reduced_mass(
)


def periodic_table_period(argument: Union[str, Integral]) -> Integral:
def periodic_table_period(argument: Union[str, int]) -> int:
"""
Return the periodic table period.

Expand Down Expand Up @@ -912,7 +913,7 @@ def periodic_table_period(argument: Union[str, Integral]) -> Integral:
return _elements.data_about_elements[symbol]["period"]


def periodic_table_group(argument: Union[str, Integral]) -> Integral:
def periodic_table_group(argument: Union[str, int]) -> int:
"""
Return the periodic table group.

Expand Down Expand Up @@ -960,7 +961,7 @@ def periodic_table_group(argument: Union[str, Integral]) -> Integral:
return _elements.data_about_elements[symbol]["group"]


def periodic_table_block(argument: Union[str, Integral]) -> str:
def periodic_table_block(argument: Union[str, int]) -> str:
"""
Return the periodic table block.

Expand Down Expand Up @@ -1011,7 +1012,7 @@ def periodic_table_block(argument: Union[str, Integral]) -> str:
return _elements.data_about_elements[symbol]["block"]


def periodic_table_category(argument: Union[str, Integral]) -> str:
def periodic_table_category(argument: Union[str, int]) -> str:
"""
Return the periodic table category.

Expand Down Expand Up @@ -1059,9 +1060,9 @@ def periodic_table_category(argument: Union[str, Integral]) -> str:

@particle_input(any_of={"element", "isotope", "ion"})
def ionic_levels(
particle: Particle,
min_charge: Integral = 0,
max_charge: Optional[Integral] = None,
particle: ParticleLike,
min_charge: int = 0,
max_charge: Optional[int] = None,
) -> ParticleList:
"""
Return a |ParticleList| that includes different ionic levels of a
Expand Down