materialsvirtuallab/monty

f-strings not supported in Python 3.5 or below

ajjackson opened this issue · 2 comments

System

  • Monty version: 2021.3.3
  • Python version: 3.5
  • OS version: Fedora 33

Summary

  • The setup.py of monty declares that Python 3.5 is supported
  • Monty contains f-strings which are not valid syntax in Python 3.5

Example code

conda create --name py35 python=3.5
conda activate py35
pip install monty
python3 -c "from monty.json import MSONable"

Error message

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/adam/.conda/envs/py35/lib/python3.5/site-packages/monty/json.py", line 224
    raise ValueError(f"Must provide {cls.__name__}, the as_dict form, or the proper")
                                                                                   ^
SyntaxError: invalid syntax

Suggested solution (if known)

  • Avoid f-strings while Python 3.5 is supported

If the intent is to use f-strings going forwards (and I am personally a fan of f-strings!), then I think the cleanest way to fix this up would be:

  • replace the f-strings with .format() equivalents
  • make a bugfix release so that Python 3.5 users will find a working version
  • restore the f-strings
  • update setup.py to require Python 3.6 or above
  • update the other references in documentation to Python 2.7, 3.x
  • make a separate release that packages these changes together

I think something went wrong: currently, pip install monty from Python 3.5 will install the (non-3.5-compatible) version 2021.5.9. (I believe the problem is the line python_requires=">=3.5" in setup.py.)

I would like to clarify that simply updating this requirement will not fix Pip installation for 3.5 users, as the most recent package marked for 3.5 on PyPI would still be an incompatible release. It is not best-practice to allow legacy installation to break when a package updates its own version requirements: for example, Numpy has also dropped support for Python 3.5, but pip install numpy will correctly install numpy-1.18.5, the last supported version.