ortk95 / planetmapper

PlanetMapper: An open source Python package for visualising, navigating and mapping Solar System observations
https://planetmapper.readthedocs.io
MIT License
10 stars 1 forks source link

Improve string representations of customised objects #362

Closed ortk95 closed 3 months ago

ortk95 commented 3 months ago

String representations (e.g. from str() or repr()) of objects now include any extra arguments used to customise the object. These arguments are only included in the string if they have been changed from their default values, keeping the string concise. For example:

body = planetmapper.Body('JUPITER', '2000-01-01T00:00:00.000000', observer='EARTH', illumination_source='Europa')

# New behaviour:
print(body)
# Body('JUPITER', '2000-01-01T00:00:00.000000', observer='EARTH', illumination_source='Europa')

# Old behaviour (note the customised illumination source was missing):
print(body)
# Body('JUPITER', '2000-01-01T00:00:00.000000', observer='EARTH')

This is implemented for all objects by defining a (private) dictionary of the default argument values used to initialise the object, then using this to automatically include non-default arguments in the string. Therefore, any new objetcs/subclasses simply need to add any new arguments to _get_default_init_kwargs, then _generate_repr can be used to automatically generate a desired string.

Closes #351.

Pull request checklist

See CONTRIBUTING.md for more details.

coveralls commented 3 months ago

Pull Request Test Coverage Report for Build 9480386153

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
planetmapper/base.py 26 27 96.3%
<!-- Total: 58 59 98.31% -->
Totals Coverage Status
Change from base Build 9416842717: -0.02%
Covered Lines: 2955
Relevant Lines: 2968

💛 - Coveralls