radio-astro-tools / radio-beam

A simple toolkit for reading and manipulating beams from astrophysical radio spectral data cubes.
https://radio-beam.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
26 stars 21 forks source link

A sneaky invalid escape? #131

Open AlecThomson opened 3 weeks ago

AlecThomson commented 3 weeks ago

Hi all,

I found something interesting on (basic import) testing a new package of mine. Nox + pytest picked up the following error on trying to import radio-beam:

__________________________________________________________________________________ ERROR collecting tests/test_package.py __________________________________________________________________________________
.nox/tests/lib/python3.11/site-packages/_pytest/python.py:493: in importtestmodule
    mod = import_path(
.nox/tests/lib/python3.11/site-packages/_pytest/pathlib.py:582: in import_path
    importlib.import_module(module_name)
../../../miniforge3/envs/arm311/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
.nox/tests/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:184: in exec_module
    exec(co, module.__dict__)
tests/test_package.py:5: in <module>
    import featherpy as m
.nox/tests/lib/python3.11/site-packages/featherpy/__init__.py:10: in <module>
    from .core import *  # noqa: F403
.nox/tests/lib/python3.11/site-packages/featherpy/core.py:17: in <module>
    from radio_beam import Beam
.nox/tests/lib/python3.11/site-packages/radio_beam/__init__.py:7: in <module>
    from .multiple_beams import Beams
E     File "/Users/tho822/My Drive/repos/FeatherPy/.nox/tests/lib/python3.11/site-packages/radio_beam/multiple_beams.py", line 337
E       '''
E       ^^^
E   SyntaxError: invalid escape sequence '\e'

The offending line seems to be here https://github.com/radio-astro-tools/radio-beam/blob/f1111a4614464d46acfbb88373e7d4fa51324ac0/radio_beam/multiple_beams.py#L337.

I can't see any funky characters directly, but it also seems to highlight the (admittedly very unimportant) inconsistent docstring quotes. Would you be open to adopting a switch to """ for all docstrings following PEP-257?

a-detiste commented 2 weeks ago

I'm not sure that helps. I used this patch:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087040

--- a/radio_beam/multiple_beams.py
+++ b/radio_beam/multiple_beams.py
@@ -334,7 +334,7 @@
                 self.largest_beam(includemask)]

     def common_beam(self, includemask=None, method='pts', **kwargs):
-        '''
+        r'''
         Return the smallest common beam size. For set of two beams,
         the solution is solved analytically. All larger sets solve for the
         minimum volume ellipse using the
keflavich commented 2 weeks ago

Yeah, the problem is in the latex. r''' is probably the right solution, though I might slightly prefer to s/\e/\\e/ (replace single-escape with double-escape) for a text block this large

AlecThomson commented 2 weeks ago

Gah, apologies for not reading down a few lines further! 🫤 I've added the latex escapes to the latex, if that's useful. I've gone with the double-escape version, but can go with the raw-string if that's preferred.