From 1ffb0d9c9eb5adfea9604a96f289bcd1480f434c Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Mon, 28 Mar 2022 21:26:26 +0200 Subject: [PATCH] Add `__init__()` to template core module The template now recommends implementing an `__init__()` function that allows the users to conveniently override the `astropy` configuration system. --- astroquery/template_module/core.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/astroquery/template_module/core.py b/astroquery/template_module/core.py index 907f34725c..36dd5be796 100644 --- a/astroquery/template_module/core.py +++ b/astroquery/template_module/core.py @@ -36,17 +36,16 @@ @async_to_sync class TemplateClass(BaseQuery): - """ - Not all the methods below are necessary but these cover most of the common - cases, new methods may be added if necessary, follow the guidelines at - - """ + # `__init__()` allows the user to conveniently set the instance attributes + # to override the configuration items. The default attribute values should + # be falsy (`x` is called falsy if `bool(x)` is `False`) or `None`. + def __init__(self, url='', timeout=None): + self.url = url # A falsy default that cannot be mistaken for a valid value. + self.timeout = timeout # Use `None` as default if the falsy value could be valid. # The private properties defined here allow the users to change the - # configuration values at runtime, or to completely override them with - # instance attributes. - url = '' # A falsy default that cannot be mistaken for a valid value. - timeout = None # Use `None` if the falsy value could be valid. + # configuration values at runtime if the corresponding instance attributes + # have default values. @property def _url(self): @@ -56,6 +55,12 @@ def _url(self): def _timeout(self): return conf.timeout if self.timeout is None else self.timeout + """ + Not all the methods below are necessary but these cover most of the common + cases, new methods may be added if necessary, follow the guidelines at + + """ + # all query methods are implemented with an "async" method that handles # making the actual HTTP request and returns the raw HTTP response, which # should be parsed by a separate _parse_result method. The query_object @@ -332,7 +337,7 @@ def extract_image_urls(self, html_str): pass -# the default tool for users to interact with is an instance of the Class +# the default tool for users to interact with is a default instance of the Class Template = TemplateClass() # once your class is done, tests should be written