Closed hongyi-zhao closed 1 month ago
In general, import statements can have side effects, so a safe autofix is not possible.
Support for an unsafe fix is tracked here: https://github.com/astral-sh/ruff/issues/6514
But even I use the --unsafe-fixes
, it still doesn't work:
(datasci) werner@x13dai-t:~/Desktop/mp_workflow$ ruff check --fix --unsafe-fixes Untitled2.py
Untitled2.py:75:1: E402 Module level import not at top of file
|
73 | # In[1]:
74 |
75 | from mp_api.client import MPRester
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E402
76 |
77 | with MPRester() as mpr:
|
Untitled2.py:87:1: E402 Module level import not at top of file
|
85 | # In[3]:
86 |
87 | from mp_api.client import MPRester
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E402
88 | from pymatgen.io.cif import CifWriter
89 | from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
|
Untitled2.py:88:1: E402 Module level import not at top of file
|
87 | from mp_api.client import MPRester
88 | from pymatgen.io.cif import CifWriter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E402
89 | from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
|
Untitled2.py:89:1: E402 Module level import not at top of file
|
87 | from mp_api.client import MPRester
88 | from pymatgen.io.cif import CifWriter
89 | from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E402
90 |
91 | # 使用你的API密钥初始化MPRester
|
Found 4 errors.
ruff doesn't currently have an unsafe fix implemented for this rule.
Discussion about adding one is here: https://github.com/astral-sh/ruff/issues/6514
Thank you for your comments.
See below:
On the other hand, the following command will fix these problems:
Below are all the mentioned files here.
Untitled2.zip
Regards, Zhao