skypyproject / skypy

SkyPy: A package for modelling the Universe.
BSD 3-Clause "New" or "Revised" License
118 stars 38 forks source link

ENH: Config syntax for importing objects #463

Closed rrjbca closed 3 years ago

rrjbca commented 3 years ago

Description

This is a proposal for an extension to the config syntax that allows objects to be imported directly from external (sub)modules using the ! tag and providing neither a list of args or a dict of kwargs. (N.B. to call a function without any arguments pass and empty list of args or an empty dict of kwargs). For example this enables:

cosmo1: !astropy.cosmology.Planck18 # import the Planck18 object and bind to cosmo1
cosmo2: !astropy.cosmology.default_cosmology.get [] # call default_cosmology.get() and bind to cosmo2

Note that as a result of the design, it is no longer possible to call a function with a single argument using a scalar node; the argument must be put into a list:

old_syntax: !len 'hello world!' # invalid
new_syntax: !len ['hello world!'] # correctly define an explicit list of args

Checklist

rrjbca commented 3 years ago

The syntax will be documented in #454