diff --git a/docs/development/code_guide.rst b/docs/development/code_guide.rst index 2c84bb650b..f4dc9e73c5 100644 --- a/docs/development/code_guide.rst +++ b/docs/development/code_guide.rst @@ -49,6 +49,9 @@ Coding Style * For multiline imports, instead of using ``\`` to break lines, wrap the imported names in ``()`` parentheses and use consistent whitespace. +* Use ``Optional[type]`` for type hinted keyword arguments with a default value of + ``None``. + * There should be at most one pun per 1284 lines of code. Branches, commits, and pull requests diff --git a/plasmapy/atomic/atomic.py b/plasmapy/atomic/atomic.py index 54ed55e309..4ea83c538b 100644 --- a/plasmapy/atomic/atomic.py +++ b/plasmapy/atomic/atomic.py @@ -260,7 +260,7 @@ def particle_mass( @particle_input -def isotopic_abundance(isotope: Particle, mass_numb: numbers.Integral = None) -> numbers.Real: +def isotopic_abundance(isotope: Particle, mass_numb: Optional[numbers.Integral] = None) -> numbers.Real: """ Return the isotopic abundances if known, and otherwise zero. @@ -422,7 +422,7 @@ def electric_charge(particle: Particle) -> u.Quantity: @particle_input -def is_stable(particle: Particle, mass_numb: numbers.Integral = None) -> bool: +def is_stable(particle: Particle, mass_numb: Optional[numbers.Integral] = None) -> bool: """ Return `True` for stable isotopes and particles and `False` for unstable isotopes. @@ -476,7 +476,7 @@ def is_stable(particle: Particle, mass_numb: numbers.Integral = None) -> bool: @particle_input(any_of={'stable', 'unstable', 'isotope'}) -def half_life(particle: Particle, mass_numb: numbers.Integral = None) -> u.Quantity: +def half_life(particle: Particle, mass_numb: Optional[numbers.Integral] = None) -> u.Quantity: """ Return the half-life in seconds for unstable isotopes and particles, and numpy.inf in seconds for stable isotopes and particles. diff --git a/plasmapy/atomic/nuclear.py b/plasmapy/atomic/nuclear.py index 16410112db..2ccc0266a5 100644 --- a/plasmapy/atomic/nuclear.py +++ b/plasmapy/atomic/nuclear.py @@ -1,7 +1,7 @@ """Functions that are related to nuclear reactions.""" from astropy import units as u -from typing import List, Union +from typing import List, Union, Optional import re from plasmapy.utils import ( @@ -20,7 +20,7 @@ @particle_input(any_of={'isotope', 'baryon'}) -def nuclear_binding_energy(particle: Particle, mass_numb: int = None) -> u.Quantity: +def nuclear_binding_energy(particle: Particle, mass_numb: Optional[int] = None) -> u.Quantity: """ Return the nuclear binding energy associated with an isotope. @@ -79,7 +79,7 @@ def nuclear_binding_energy(particle: Particle, mass_numb: int = None) -> u.Quant @particle_input -def mass_energy(particle: Particle, mass_numb: int = None) -> u.Quantity: +def mass_energy(particle: Particle, mass_numb: Optional[int] = None) -> u.Quantity: """ Return a particle's mass energy. If the particle is an isotope or nuclide, return the nuclear mass energy only. diff --git a/plasmapy/atomic/symbols.py b/plasmapy/atomic/symbols.py index 71b1fff1b2..25df84d39b 100644 --- a/plasmapy/atomic/symbols.py +++ b/plasmapy/atomic/symbols.py @@ -3,6 +3,8 @@ and numbers. """ +from typing import Optional + from .particle_class import Particle from .particle_input import particle_input import numbers @@ -94,7 +96,7 @@ def atomic_symbol(element: Particle) -> str: @particle_input -def isotope_symbol(isotope: Particle, mass_numb: numbers.Integral = None) -> str: +def isotope_symbol(isotope: Particle, mass_numb: Optional[numbers.Integral] = None) -> str: """ Return the symbol representing an isotope. diff --git a/plasmapy/physics/parameters.py b/plasmapy/physics/parameters.py index c5984ef6bb..86f78b2986 100644 --- a/plasmapy/physics/parameters.py +++ b/plasmapy/physics/parameters.py @@ -3,6 +3,8 @@ plasma frequency or Debye length. """ +from typing import Optional + __all__ = [ "mass_density", "Alfven_speed", @@ -64,7 +66,7 @@ def _grab_charge(ion, z_mean=None): return Z -def mass_density(density, particle: str = None, z_mean: numbers.Real = None) -> u.kg / u.m ** 3: +def mass_density(density, particle: Optional[str] = None, z_mean: Optional[numbers.Real] = None) -> u.kg / u.m ** 3: """Utility function to merge two possible inputs for particle charge. Parameters