Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ritiek committed Jun 9, 2018
1 parent f574d61 commit 5c02dc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
11 changes: 3 additions & 8 deletions plasmapy/atomic/particle_input.py
Expand Up @@ -129,10 +129,7 @@ def particle_input(wrapped_function: Callable = None,
`TypeError`
If the annotated argument is not a `str`, `int`, `tuple`, `list`
or `~plasmapy.atomic.Particle`; or if `Z` or `mass_numb` is
not an `int`; or if number of elements in a tuple do not match
the expected parameters; or if invalid list annotations in
function declaration; or if a `tuple` or a `list` is passed when
function only expects a single Particle as `str` or `int` instead.
not an `int`.
`~plasmapy/utils/InvalidParticleError`
If the annotated argument does not correspond to a valid
Expand Down Expand Up @@ -255,10 +252,8 @@ def wrapper(*args, **kwargs):
expected_params = len(annotated_argnames)
if expected_params > 1:
raise TypeError(
f"A list can take any number of parameters "
f"without explictly mentioning the number of "
f"parameters in declaration. Use a tuple "
f"instead or '[Particle]' should be enough.")
f"Put in [Particle] as the annotation to "
f"accept arbitrary number of Particle arguments."
else:
annotated_argnames = (annotations[argname],)

Expand Down
18 changes: 9 additions & 9 deletions plasmapy/atomic/tests/test_particle_input.py
Expand Up @@ -176,12 +176,13 @@ def test_function_with_ambiguity():
def function_to_test_annotations(particles: Union[Tuple, List], resulting_particles):
"""
Test that a function with an argument annotated with (Particle,
Particle) returns a tuple of the two expected Particle instances.
Particle, ...) or [Particle] returns a tuple of expected Particle
instances.
Arguments
=========
particles: tuple or list
A collection containing two items, each of which may be a valid
A collection containing many items, each of which may be a valid
representation of a particle or a `~plasmapy.atomic.Particle`
instance
Expand All @@ -202,16 +203,15 @@ def function_to_test_annotations(particles: Union[Tuple, List], resulting_partic

if not returned_particle_instances:
raise AtomicError(
f"A function decorated by particle_input with an annotation"
f" of (Particle, Particle) did not return a tuple of two "
f"Particle instances for inputs of {repr(particles)}, and "
f"instead returned {repr(resulting_particles)}.")
f"A function decorated by particle_input did not return "
f"a tuple of Particle instances for input of "
f"{repr(particles)}, and instead returned"
f"{repr(resulting_particles)}.")

if not returned_correct_instances:
raise AtomicError(
f"A function decorated by particle_input with an annotation"
f" of (Particle, Particle) did not return {repr(expected)} "
f"as expected, and instead returned "
f"A function decorated by particle_input did not return "
f"{repr(expected)} as expected, and instead returned "
f"{repr(resulting_particles)}.")


Expand Down

0 comments on commit 5c02dc4

Please sign in to comment.