Skip to content

Commit

Permalink
Add __init__() to template core module
Browse files Browse the repository at this point in the history
The template now recommends implementing an `__init__()` function that
allows the users to conveniently override the `astropy` configuration
system.
  • Loading branch information
eerovaher committed Mar 28, 2022
1 parent 5137807 commit 1ffb0d9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions astroquery/template_module/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<http://astroquery.readthedocs.io/en/latest/api.html>
"""
# `__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):
Expand All @@ -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
<http://astroquery.readthedocs.io/en/latest/api.html>
"""

# 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1ffb0d9

Please sign in to comment.