pythonastropyply

Can't run code with astropy using -OO flag


My code runs in python as expected with no python flags, or with the -O flag. It does not work with the -OO flag. My code uses astropy. Astropy is a python package that includes multiple subpackages and used 3rd party code ply.

I have reduced my code to the simplest way to reproduce the error. The content of minimalTest.py is:

import astropy.coordinates
print('hello world')

The following 2 commands work as expected (each prints 'hello world'):

# python3 minimalTest.py
# python3 -O minimalTest.py

The following produces an error:

# python3 -OO minimalTest.py
Traceback (most recent call last):
  File "/tmp/minimalTest.py", line 1, in <module>
    import astropy.coordinates
  File "/usr/local/lib/python3.9/site-packages/astropy/coordinates/__init__.py", line 13, in <module>
    from .builtin_frames import *
  File "/usr/local/lib/python3.9/site-packages/astropy/coordinates/builtin_frames/__init__.py", line 30, in <module>
    from .cirs import CIRS
  File "/usr/local/lib/python3.9/site-packages/astropy/coordinates/builtin_frames/cirs.py", line 8, in <module>
    from .utils import DEFAULT_OBSTIME, EARTH_CENTER
  File "/usr/local/lib/python3.9/site-packages/astropy/coordinates/builtin_frames/utils.py", line 16, in <module>
    from astropy.utils import iers
  File "/usr/local/lib/python3.9/site-packages/astropy/utils/iers/__init__.py", line 1, in <module>
    from .iers import *
  File "/usr/local/lib/python3.9/site-packages/astropy/utils/iers/iers.py", line 23, in <module>
    from astropy.table import MaskedColumn, QTable
  File "/usr/local/lib/python3.9/site-packages/astropy/table/__init__.py", line 118, in <module>
    import astropy.io.ascii.connect
  File "/usr/local/lib/python3.9/site-packages/astropy/io/ascii/__init__.py", line 8, in <module>
    from .basic import (
  File "/usr/local/lib/python3.9/site-packages/astropy/io/ascii/basic.py", line 44, in <module>
    class Basic(core.BaseReader):
  File "/usr/local/lib/python3.9/site-packages/astropy/io/ascii/core.py", line 1233, in __init__
    func.__doc__ += inspect.cleandoc(cls.__doc__).strip()
  File "/usr/local/lib/python3.9/inspect.py", line 632, in cleandoc
    lines = doc.expandtabs().split('\n')
AttributeError: 'NoneType' object has no attribute 'expandtabs'

I think the problem may be related to https://github.com/astropy/astropy/issues/10361 which was closed a few years ago. This issue was related to how ply (3rd party code used by astropy) handles docstrings.

I have reproduced this issue on Centos7 with Python 3.9.10 and Windows10 with Python 3.11.2.


Solution

  • Astropy code base has been updated to add support for -OO flag. https://github.com/astropy/astropy/pull/15037

    Note that this update did not fix the compatibility issues between Astropy and Nuitka, but this is being tracked directly on their github pages.