From 5c02dc40cb6547324ff745471b67d412672bd939 Mon Sep 17 00:00:00 2001 From: ritiek Date: Sat, 9 Jun 2018 18:48:46 +0530 Subject: [PATCH] Improve documentation --- plasmapy/atomic/particle_input.py | 11 +++-------- plasmapy/atomic/tests/test_particle_input.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/plasmapy/atomic/particle_input.py b/plasmapy/atomic/particle_input.py index 7f1df5caec..3f2fb84ee7 100644 --- a/plasmapy/atomic/particle_input.py +++ b/plasmapy/atomic/particle_input.py @@ -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 @@ -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],) diff --git a/plasmapy/atomic/tests/test_particle_input.py b/plasmapy/atomic/tests/test_particle_input.py index 9389ac9dfc..a5a7017f7e 100644 --- a/plasmapy/atomic/tests/test_particle_input.py +++ b/plasmapy/atomic/tests/test_particle_input.py @@ -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 @@ -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)}.")