Skip to content

Wrapper to create non-async methods from all async methods in a class - #149

Merged
keflavich merged 13 commits into
astropy:masterfrom
keflavich:async_to_func
Aug 7, 2013
Merged

keflavich merged 13 commits into
astropy:masterfrom
keflavich:async_to_func

Conversation

@keflavich

Copy link
Copy Markdown
Contributor

Since all of the query_x tools are trivial wrappers on top of query_x_async, they are taking up a lot of lines of code without adding any useful functionality. Therefore, for the sake of code readability and maintenance, it makes sense to use a generator function.

This PR implements the generator, which would be applied to any class with _async methods, e.g. in Vizier/core.py you would do:

process_asyncs(Vizier)

@keflavich

Copy link
Copy Markdown
Contributor Author

@jdnc - it would be great if you could give this a try on your next module.

@jdnc

jdnc commented Aug 5, 2013

Copy link
Copy Markdown
Contributor

Sure I 'll try this for the NIST that I'm doing next. One question is that currently this won't be able to generate automatically from get_images_async methods?

@keflavich

Copy link
Copy Markdown
Contributor Author

I think not; we may need a different wrapper for that.

There are definitely still kinks to work out:

  1. This should be used as a decorator on a class, which is neat, but it's untested
  2. The docstring inheritance "stuff" doesn't work yet. I haven't figured out why, but hopefully will soon.

@keflavich keflavich mentioned this pull request Aug 5, 2013
@keflavich

Copy link
Copy Markdown
Contributor Author

I'll merge this as soon as splatalogue tests pass; splatalogue actually makes use of this module & tests it directly

@keflavich

Copy link
Copy Markdown
Contributor Author

(@jdnc - FYI)
This PR now includes docstring parser/chomper code so that the methods can all properly include docstrings.

See splatalogue for an example, but basically I've taken this approach:

  1. Put all of the keyword argument descriptions in _parse_args
  2. query_..._async inherits the _parse_args docstr but with a different Returns block
  3. Ditto query_....: different Returns block

If _parse_args is not unique to a query function, it can't be inherited in this way, though.

keflavich added a commit that referenced this pull request Aug 7, 2013
Wrapper to create non-async methods from all async methods in a class
@keflavich
keflavich merged commit 5cc7251 into astropy:master Aug 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants