Module import pattern causes randomly timed exceptions to be raised
- Dominant language
- Python
- Stars
- 791
- Forks
- 451
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 4
Description
[This line,](https://github.com/astropy/astroquery/blob/74fb75d0ac253e4b14d0f42bb67147a9bc53f672/astroquery/simbad/core.py#L1147) which allows people to do queries in the following way, causes signficant bad side effects, as follows:
```
from astroquery.simbad import Simbad
result = Simbad.query_object("HD12345")
... etc ...
```
Apologies if these words are a little imprecise, but, because the module import itself ends up functioning as a class, the resulting "object" doesn't drop out of scope, because it's an import not a normal instance of a class. This means that when the underlying connection goes stale/times out, an exception is raised at some random time in the future, causing whatever process is running to fall over with a very confusing error, as it doesn't relate to any code that is running at that point.
There are likely many others, but a simple fix (which would, however, mean an API change) would, I think, be just to remove that line, so as to enfore people explictly making class instances, which will then be cleaned up as one would expect, _e.g._ forcing
```
from astroquery.simbad import SimbadClass
simbad = SimbadClass()
... etc ...
```
as the usage pattern. It might also be that simply having people do `simbad.Simbad()` rather than `simbad.Simbad` (without the parens) would also work.
Finally, it might also be worth noting that this `Simbad` is an instance, not a class definition, and therefore has the wrong capitalization.
Contributor guide
Research direction
Start at astroquery/simbad/core.py line 1147 and inspect how the exported Simbad object is created and used by the documented query pattern. Compare that behavior with the proposed SimbadClass() and Simbad() alternatives, then determine the API and cleanup behavior that should be supported. Done means the import pattern no longer causes delayed, unrelated exceptions and the intended usage is documented and tested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100