Skip to content

Commit 1ffb0d9

Browse files
committed
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.
1 parent 5137807 commit 1ffb0d9

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

astroquery/template_module/core.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@
3636
@async_to_sync
3737
class TemplateClass(BaseQuery):
3838

39-
"""
40-
Not all the methods below are necessary but these cover most of the common
41-
cases, new methods may be added if necessary, follow the guidelines at
42-
<http://astroquery.readthedocs.io/en/latest/api.html>
43-
"""
39+
# `__init__()` allows the user to conveniently set the instance attributes
40+
# to override the configuration items. The default attribute values should
41+
# be falsy (`x` is called falsy if `bool(x)` is `False`) or `None`.
42+
def __init__(self, url='', timeout=None):
43+
self.url = url # A falsy default that cannot be mistaken for a valid value.
44+
self.timeout = timeout # Use `None` as default if the falsy value could be valid.
4445

4546
# The private properties defined here allow the users to change the
46-
# configuration values at runtime, or to completely override them with
47-
# instance attributes.
48-
url = '' # A falsy default that cannot be mistaken for a valid value.
49-
timeout = None # Use `None` if the falsy value could be valid.
47+
# configuration values at runtime if the corresponding instance attributes
48+
# have default values.
5049

5150
@property
5251
def _url(self):
@@ -56,6 +55,12 @@ def _url(self):
5655
def _timeout(self):
5756
return conf.timeout if self.timeout is None else self.timeout
5857

58+
"""
59+
Not all the methods below are necessary but these cover most of the common
60+
cases, new methods may be added if necessary, follow the guidelines at
61+
<http://astroquery.readthedocs.io/en/latest/api.html>
62+
"""
63+
5964
# all query methods are implemented with an "async" method that handles
6065
# making the actual HTTP request and returns the raw HTTP response, which
6166
# should be parsed by a separate _parse_result method. The query_object
@@ -332,7 +337,7 @@ def extract_image_urls(self, html_str):
332337
pass
333338

334339

335-
# the default tool for users to interact with is an instance of the Class
340+
# the default tool for users to interact with is a default instance of the Class
336341
Template = TemplateClass()
337342

338343
# once your class is done, tests should be written

0 commit comments

Comments
 (0)